这一篇先给大家介绍最基本的UI美化知识,下一篇给大家上一个实例;
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape=["rectangle" | "oval" | "line" | "ring"] > --- 默认为rectangle,矩形
<corners -- shape=“rectangle”时使用, 常用
android:radius="integer" -- 半径,会被下边的属性覆盖,默认为1dp,
android:topLeftRadius="integer"
android:topRightRadius="integer"
android:bottomLeftRadius="integer"
android:bottomRightRadius="integer"/>
<gradient -- 渐变
android:angle="integer" --angle表示方向角度。当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上
android:centerX="integer"
android:centerY="integer"
android:centerColor="integer"
android:endColor="color"
android:gradientRadius="integer"
android:startColor="color"
android:type=["linear" | "radial" | "sweep"]
android:useLevel=["true" | "false"] />
<padding --内边距
android:left="integer"
android:top="integer"
android:right="integer"
android:bottom="integer"/>
<size -- 指定大小,一般用在imageview配合scaleType属性使用。大小一般会适配滴
android:width="integer"
android:height="integer"/>
<solid -- 填充颜色,可是是十六进制颜色。(比如想设置半透明效果,直接使用十六进制就OK)
android:color="color"/>
<stroke -- 指定边框,border,dashWidth和dashGap有一个为0dp则为
android:width="integer"
android:color="color"
android:dashWidth="integer" -- 虚线宽度
android:dashGap="integer"/> -- 虚线间隔宽度
</shape>
solid:实心,就是填充的意思
android:color指定填充的颜色
gradient:渐变
android:startColor和android:endColor分别为起始和结束颜色,
ndroid:angle是渐变角度,必须为45的整数倍。
另外渐变默认的模式为android:type="linear",即线性渐变,可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50"。
stroke:描边
android:width="2dp" 描边的宽度,android:color 描边的颜色。
我们还可以把描边弄成虚线的形式,设置方式为:
android:dashWidth="5dp"
android:dashGap="3dp"
其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离。
corners:圆角
android:radius为角的弧度,值越大角越圆。
注意:
<corners>
1、android:radius,半径,会被下边的单个角度半径属性覆盖,默认为1dp,
2、在使用时,如果单独设置四个角度,又大小不一致时,eclipse的graphics preview会报错。但是直接真机运行即可。(比如实线上边直角,下边屈角的效果)
<二> state解释
Android:drawable :放一个drawable资源
android:state_pressed :是否按下,如一个按钮触摸或者点击。
android:state_focused :是否取得焦点,比如用户选择了一个文本框。
android:state_hovered :光标是否悬停,通常与focused state相同,它是4.0的新特性
android:state_selected :被选中,它与focus state并不完全一样,如一个list view 被选中的时候,它里面的各个子组件可能通过方向键,被选中了。
android:state_checkable :组件是否能被check。如:RadioButton是可以被check的。
android:state_checked :被checked了,如:一个RadioButton可以被check了。
android:state_enabled :能够接受触摸或者点击事件
android:state_activated 被激活
android:state_window_focused :应用程序是否在前台,当有通知栏被拉下来或者一个对话框弹出的时候应用程序就不在前台了
注意:如果有多个item,那么程序将自动从上到下进行匹配,最先匹配的将得到应用。(不是通过最佳匹配)
如果一个item没有任何的状态说明,那么它将可以被任何一个状态匹配。