<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#f033ff22"/>
<stroke android:width="2dp" android:color="#ff1111" android:dashWidth="2dp"
android:dashGap="0dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
<corners android:radius="6dp" />
</shape>
solid中定义的颜色值需要包含alpha值,

stroke可以定义边框的颜色,width为边框的宽度,dashWidth为画笔的宽度,dashGap为画笔的间距

(dashGap为0,则边框为实心的边线)

corners定义四角圆弧的半径。

TIP:

对于使用selector定义不同的状态也可以使用shape替代drawable的属性。

view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false"
android:drawable="@drawable/gallery_selected_unfocused" />
<item android:state_focused="true"
android:drawable="@drawable/gallery_selected_focused" />
<item android:state_pressed="true"
android:drawable="@drawable/gallery_unselected_focused" />
<item android:state_selected="true"
android:drawable="@drawable/gallery_unselected_focused" />
</selector>
--->>>

view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false" >
<shape>
<solid ...>
</solid>
</shape>
</item>
<item android:state_focused="true" >
<shape>
<solid ...>
</solid>
</shape>
</item>
<item android:state_pressed="true" >
<shape>
<solid ...>
</solid>
</shape>
</item>
</selector>
我们今天来说一说怎么样让你的Button更炫一些,如果把这个添加到你的游戏里,你就会让你的游戏更吸引玩家,android为我们提供了太多难以想象的效果,那么我们就来看看这个效果怎么样来实现吧,我们还是先来看看效果图:

完事我们就来看看代码吧。让我们尽情的想象我们的界面有多么的炫吧。

Java代码:

<?xml version="1.0" encoding="utf-8"?>

< selector //view的各种状态(正常无焦点,焦点,onclick按下、放开等等)

xmlns:android="http://schemas.android.com/apk/res/android">

< item android:state_pressed="true" > //选中未up时

< shape>

< gradient //颜色渐变

android:startColor="#ff8c00" //开始颜色

android:endColor="#FFFFFF" //结束颜色

android:angle="270" /> //渐变方向

< stroke //按钮边缘

android:width="2dp" //边缘宽

android:color="#dcdcdc" /> //边缘颜色

< corners //按钮四个圆角

android:radius="2dp" /> //半径

< padding //按钮文字和边缘距离(内边距)

android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp" />

< /shape>

< /item>

< item android:state_focused="true" > //焦点

< shape>

< gradient

android:startColor="#ffc2b7"

android:endColor="#ffc2b7"

android:angle="270" />

< stroke

android:width="2dp"

android:color="#dcdcdc" />

< corners

android:radius="2dp" />

< padding

android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp" />

< /shape>

< /item>

< item> //无焦点

< shape>

< gradient

android:startColor="#ff9d77"

android:endColor="#ff9d77"

android:angle="270" />

< stroke

android:width="2dp"

android:color="#fad3cf" />

< corners

android:radius="2dp" />

< padding

android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp" />

< /shape>

< /item>

< /selector>


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xinke87/archive/2011/05/22/6438422.aspx

更多相关文章

  1. RelativeLayout属性详解
  2. android布局属性
  3. Android(安卓)Layout 属性大全
  4. Selector与Shape的基本用法
  5. android布局属性详解
  6. Android(安卓)xml 深入解析shape
  7. Android-----RelativeLayout属性
  8. 第21天android:《android从零开始》视频(10-13)
  9. android布局属性详解

随机推荐

  1. Android图表控件MPAndroidChart——曲线
  2. Android中的CheckBox
  3. 【Android】 ListView之setEmptyView的问
  4. react native之修改APP的名称和图标
  5. 关于声明文件中android:process属性说明
  6. android 文件系统(
  7. Android学习笔记:框架模式
  8. android - 5大UI设计技巧
  9. Android 八款开源 Android 游戏引擎
  10. 在Android中查看和管理sqlite数据库