Android:shape、XML绘图
2013-06-20 22:06
281 查看
1.线line:
2.椭圆oval:
3.长方形rectangle:
4.填充颜色solid、渐变gradient、边角corners:
5.代码编写
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <stroke android:width="8dp" android:color="#ff00ff00" android:dashWidth="6dp" android:dashGap="2dp"/> </shape>
2.椭圆oval:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <solid android:color="#ff345678"/> <stroke android:width="20dp" android:color="#ff876543"/> </shape>
3.长方形rectangle:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <size android:width="200dp" android:height="300dp"/> <solid android:color="#ff665544"/> <stroke android:width="20dp" android:color="#445566" android:dashWidth="40dp" android:dashGap="5dp"/> </shape>
4.填充颜色solid、渐变gradient、边角corners:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <size android:width="200dp" android:height="300dp"/> <solid android:color="#ff665544"/> <stroke android:width="20dp" android:color="#445566" android:dashWidth="40dp" android:dashGap="5dp"/> <gradient android:startColor="#ff5533aa" android:centerColor="#ff996633" android:endColor="#ff114477" android:angle="135" /> <corners android:topLeftRadius="45dp" android:topRightRadius="45dp" android:bottomLeftRadius="135dp" android:bottomRightRadius="135dp"/> <!-- android:radius="45dp" --> <!-- 渐变角度 只能被45整除 --> </shape>
5.代码编写
//白色背景shape int strokeWidth = 5; // 3dp int roundRadius = 15; // 8dp int strokeColor = Color.parseColor("#2E3135"); int fillColor = Color.parseColor("#DFDFE0"); GradientDrawable gd = new GradientDrawable(); gd.setColor(fillColor); gd.setCornerRadius(roundRadius); gd.setStroke(strokeWidth, strokeColor);
相关文章推荐
- Android xml绘图(二)-----------Shape
- Android 绘图XML——Shape
- Android XML绘图shape 圆角
- Android中XML绘图:Bitmap/Shape/Seletor和Layer
- Android XML绘图Shape虚线
- Android XML绘图Shape阴影
- Android XML绘图精炼详解第(一)课:Shape解析和示例
- android xml 绘图 shape 解析
- Android中xml中shape的属性助记
- Android中Shape、selector在xml中的使用、切换按钮的背景图案
- Android 绘图XML——Selector
- Android Studio2.2在drawable文件夹创建xml的shape文件
- Android下基于XML的Graphics shape的高级UI设计,定义圆角背景等
- Android之XML的shape使用
- [Android进阶笔记]XML相关——Selector、Shape、Styles
- android shape.xml 属性详解
- Android小白的探索:2D绘图之Android简易版Microsoft Visio学习之路 二、 自定义xml生成与解析
- android中通过自定义xml实现你需要的shape效果 xml属性配置
- Android中在xml中使用shape美化UI
- Android中xml中shape的属性助记