android使用xml实现一些常用的背景图
来源:互联网 发布:庞培法布拉大学知乎 编辑:程序博客网 时间:2024/05/17 18:44
有图有真相,先上图
第一部分使用shape实现
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 渐变颜色 : android:angle渐变方向角度 android:endColor结束角度 android:startColor起始角度 --> <gradient android:angle="90" android:endColor="#FFFFFF" android:startColor="#000000" /> <!-- 圆角半径 --> <corners android:bottomLeftRadius="12dp" android:bottomRightRadius="12dp" android:topLeftRadius="12dp" android:topRightRadius="12dp" /> <!-- 1、虚线 android:dashWidth="5dp" android:dashGap="3dp" 去掉这两句就会变成实线 --> <stroke android:dashGap="3dp" android:dashWidth="5dp" android:width="2dip" android:color="#000000" /> <!-- 与中心距离 --> <padding android:bottom="12dp" android:left="12dp" android:right="12dp" android:top="12dp" /></shape>
有了样式后,再加上点击事件
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape> <!-- 渐变 --> <gradient android:endColor="#FFFFFF" android:gradientRadius="50" android:startColor="#ff8c00" android:type="radial" /> <!-- 描边 --> <stroke android:dashGap="3dp" android:dashWidth="5dp" android:width="2dp" android:color="#dcdcdc" /> <!-- 圆角 --> <corners android:radius="2dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape></item> <item android:state_focused="true"><shape> <gradient android:angle="270" android:endColor="#ffc2b7" android:startColor="#ffc2b7" /> <stroke android:width="2dp" android:color="#dcdcdc" /> <corners android:radius="2dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape></item> <item><shape> <solid android:color="#ff9d77" /> <stroke android:width="2dp" android:color="#fad3cf" /> <corners android:bottomLeftRadius="15dp" android:bottomRightRadius="0dp" android:topLeftRadius="0dp" android:topRightRadius="15dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape></item></selector>
有些情况会用到只需要某几条边有线条
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 边框框颜色值 --> <item> <shape> <solid android:color="#000000" /> </shape> </item> <!-- 主体背景颜色值 --> <item android:bottom="1dp" android:top="1dp"> <shape> <solid android:color="#ffffff" /> </shape> </item></layer-list>
http://download.csdn.net/detail/taven/8409591
欢迎加入Android交流群:31253751
0 0
- android使用xml实现一些常用的背景图
- Android 使用XML实现按钮改变焦点设置背景图
- Android动画背景图自动播放的实现
- Android动画背景图自动播放的实现
- Android动画背景图自动播放的实现
- 整理一些常用的android权限(xml)
- Android一些不太常用XML文件属性的总结
- 使用dom4j来处理xml的一些常用方法
- Android animation 动画背景图自动播放的实现
- Android动画背景图自动播放的实现程序
- Android animation 动画背景图自动播放的实现
- Android animation 动画背景图自动播放的实现
- 使用android studio常用的一些快捷键以及常用权限
- Android开发,使用背景图(xml drawable)为view 设置边框
- Android设置窗口的背景图
- Android设置窗口的背景图
- 【Android】菜单功能的实现:使用XML
- xml布局文件里直接使用背景图导致爆内存的情况处理
- 安卓颜色变换矩阵
- arcgis地图数据集合
- NSOperation vs. GCD
- Data truncation: Out of range value
- codeforces288 E. Arthur and Brackets
- android使用xml实现一些常用的背景图
- 页游服务器压力测试方案
- URLConnectionClient_Classic::invalidateAsync crash分析解决
- openwrt中luci学习笔记
- 在Ubutu14.04下,如何用OpenJTAG+OPENOCD烧写程序
- 夏普Zaurus(qtopia系统)停产 退出PDA市场
- ajaxFileUplad 异步图片上传(不支持跨域)
- acm1002
- 运行ldconfig后,导致Gnome出现的问题