圆角图片
main_item_gridview_bac.xml,一张淡灰色的圆角背景图。
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#11000000" /> <!-- radius="20dip"等价于android:bottomLeftRadius="20dip" & android:bottomRightRadius="20dip" & android:topLeftRadius="20dip" & android:topRightRadius="20dip" --> <corners android:radius="20dip" /> </shape>
这里的radius的值最好不要写死,因为在不同的尺寸(密度)的屏幕下显示效果不一定是一致的,处理方法:在各个values下的dimens.xml文件里建立radius的引用。让不同尺寸(密度)的手机,都能适配。如:
res/values-xhdpi/dimens.xml
<resources> <dimen name="gridview_vertical_space">20dp</dimen> </resources>
res/values-xxhdpi/dimens.xml
<resources> <dimen name="gridview_vertical_space">30dp</dimen> </resources>
最后将以上背景图的代码引用改写
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#11000000" /> <corners android:radius="@dimen/gridview_vertical_space" /> </shape>
solid--图形(Shape)的背景色
stroke--图形的边框,边框又可设置是否虚线,边框颜色,边框粗细等属性
padding--图形里的内容距离边框的距离
size--图形的大小(长&宽)
corners--图形的圆角,只有在图形是矩形的时候才可使用此属性(Applies only when the shape is a rectangle.)
gradient--图形渐变色
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
13.10.14
http://kofi1122.blog.51cto.com/2815761/521605