您的位置:首页 > 移动开发 > Android开发

Android:shape、XML绘图

2013-06-20 22:06 281 查看
1.线line:
<?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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shape XML绘图