Android shap 控件美化
16lz
2021-01-23
android中我们一般通过给控件设置png图片来改变控的外观,shap也能定义简单的图形来完成同样的的功能。
shap在drawable目录下,根节点为shap。
1.圆形或者椭圆形
android:shape="oval" 椭圆
solid 颜色
控件长宽相等时显示圆,不相等时椭圆
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <solid android:color="#55000000" /></shape>使用时与drawable下的资源方式相同
<TextView android:id="@+id/textview1" android:layout_width="30dp" android:layout_height="30dp" android:background="@drawable/textview_bg" />
android:shape="rectangle" 矩形
corners 半径,可以分别对四个角设半径
</pre><pre name="code" class="html"><span style="font-size:10px;"><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:bottomLeftRadius="10dip" android:bottomRightRadius="10dip" android:topLeftRadius="10dip" android:topRightRadius="10dip" /> <solid android:color="#55000000" /></shape></span>
3.渐变
gradient渐变
startColor 起始颜色
endColor 结束颜色
angle 渐变角度
padding 与控件边缘的距离
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF" android:angle="45"/> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="8dp" /></shape>
4.边框效果
stroke 边框,可以设置颜色和宽度
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:bottomLeftRadius="10dip" android:bottomRightRadius="10dip" android:topLeftRadius="10dip" android:topRightRadius="10dip" /> <solid android:color="#55000000" /> <stroke android:width="4dip" android:color="@android:color/white"/></shape>
5.圆环效果
就是shape="oval" 椭圆 加上 stroke边框
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <corners android:bottomLeftRadius="10dip" android:bottomRightRadius="10dip" android:topLeftRadius="10dip" android:topRightRadius="10dip" /> <solid android:color="#55000000" /> <stroke android:width="4dip" android:color="@android:color/white"/></shape>
更多相关文章
- Untity3D项目调用Android 图片错乱问题
- android shape ring 画一个多层嵌套的圆环和圆角图片
- [Android] ListView (普通列表控件) 的基本使用方法
- Android中图片压缩分析(上)
- android中图片的三级cache策略(内存、文件、网络)之三:文件缓存策略
- 自定义控件及效果
- YUV420P、YUV420SP、NV12、NV21和RGB互相转换并存储为JPEG以及PN
- Android 的表格控件GridView学习