Android下基于XML的Graphics shape使用方法
??Android下基于XML的 Graphics
以前作图,一般有两种方式,首先是UI把图形设计好,我们直接贴,对于那些简单的图形,如矩形、扇形这样的图
形,一般的系统的API会提供这样的接口,但是在Android下,有第三种画图方式,介于二者之间,结合二者的长处,如
下的代码:?
这是一个Progress的style里面的代码,描述的是进度条的为达到的图形,原本以为这是一个图片,后来仔细的跟踪代码,
发现居然是 xml,像这种shape corners gradient等等这还是第一次碰到。shape 表示是一个图形,corners表示是有半径
为5像素的圆角,然后,gradient表示一个渐变。这样作图简单明了,并且可以做出要求很好的图形,并且节省资源
gradient 产生颜色渐变 android:angle 从哪个角度开始变 貌似只有90的整数倍可以
android:shape="rectangle" 默认的也是长方形?#ff4100ff蓝色#ff4100ff绿色
<solid android:color="#ff4100ff"/>实心的 填充里面
<stroke 描边 采用那样的方式将外形轮廓线画出来
android:dashWidth="3dp" android:dashGap="2dp" 默认值为0
android:width="2dp" android:color="#FF00ff00"笔的粗细,
android:dashWidth="5dp" android:dashGap="5dp" 实现- - -这样的效果,dashWidth指的是一条小横线的宽度
dashGap 指的是 小横线与小横线的间距。 width="2dp" 不能太宽
shape等特殊xml
1.用 shape 作为背景?
一定要注意solid android:color="#f0600000" 是背景色 要用8位 最好不要完全透明不然没有效果啊 这句话本来就不
是背景色 的意思
2.类似多选的效果:
(1) listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setItemsCanFocus(false);
(2) define list item?3.
?4. 当设置?? TextView setEnabled(false)时 背景颜色你如果用#ffff之类的话可能不会显示 你最好使用 android:textColor这个属性而不是使用color。
?
res/color/example.xml):
?
http://developer.android.com/intl/zh-CN/reference/android/content/res/ColorStateList.html
5.?
You can simple combine several drawables into one using <layer-list> tag.
note: Unfortenately you cannot resize drawables in layer-list. You can only move it.?
include
You can put similar layout elements into separate XML and use <include> tag to use it.?
track_list_item_common.xml<merge xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:id="@+id/icon" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="4dip" android:layout_width="60px" android:layout_height="60px"/>...</merge>??