Shape use, gradient, split line, border, translucent, translucent shadow effect.
Let's start with a quick look at the properties common in shape. (Refer to the API documentation for more information)
Reprint Please specify: rflyee_: http://blog.csdn.net/rflyee/article/details/20785495
<?xml version= "1.0" encoding= "Utf-8"?>
<shape
Xmlns:android= "Http://schemas.android.com/apk/res/android"
android:shape=["Rectangle" | "Oval" | "Line" | "Ring"] >---default to Rectangle
<corners--shape= "rectangle" when used,
android:radius= "integer"-radius, will be overridden by the properties below, default to 1DP,
android:topleftradius= "Integer"
android:toprightradius= "Integer"
android:bottomleftradius= "Integer"
android:bottomrightradius= "integer"/>
<gradient--Gradient
Android:angle= "Integer"
android:centerx= "Integer"
android:centery= "Integer"
Android:centercolor= "Integer"
android:endcolor= "Color"
android:gradientradius= "Integer"
android:startcolor= "Color"
android:type=["Linear" | "Radial" | "Sweep"]
Android:uselevel=["true" | "False"]/>
<padding
android:left= "Integer"
android:top= "Integer"
android:right= "Integer"
android:bottom= "integer"/>
<size--Specifies the size, generally used in the ImageView mate ScaleType attribute. The size is usually adapted to the drip
Android:width= "Integer"
android:height= "integer"/>
<solid--fill color, but hexadecimal color. (For example, if you want to set a translucent effect, use 16 directly just OK)
android:color= "Color"/>
<stroke--Specifies the border, border,dashwidth and Dashgap have a solid line of 0DP
Android:width= "Integer"
android:color= "Color"
Android:dashwidth= "integer"--Dashed width
android:dashgap= "integer"/>--dash interval width
</shape>
Note: <corners>1, Android:radius, radius, will be overridden by the individual angle RADIUS attribute below, default is 1dp,2, when used, if four angles are set separately, and the size is inconsistent, Eclipse's graphics Preview will error. But the direct real machine can run. (for example, the real-line upper right angle, the effect of the lower flexion angle) <size>note:the shape scales to the size of the container View proportionate to the dimensions de Fined here, by default. When you use the shape
ImageView
, you can restrict scaling by setting the
android:scaleType
To
"center"
Give me a chestnut:
1. Gradual discoloration
res/drawable/gradient_box.xml
:
<?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= "/>"
<padding android:left= "7DP"
android:top= "7DP"
android:right= "7DP"
android:bottom= "7DP"/>
<corners android:radius= "8DP"/>
</shape>
2, white border, translucent effect
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="Rectangle" >
- <corners android:radius="16DP" />
- <!--This is translucent and can also be set to full transparency, which is the effect of the white border--
- <solid android:color="#80065e8d" />
- <stroke
- android:dashgap="0DP"
- android:width="4DP"
- android:color="@android: Color/white" />
- </shape>
3. Split Line effect:
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="line" >
- <stroke
- android:width="4DP"
- android:color="@android: Color/black" />
- </shape>
If: 4, unilateral angle effect
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <shape android:shape="Rectangle" xmlns:android= "http://schemas.android.com/apk/res/ Android ">
- <Corners
- android:topleftradius="5DP"
- android:toprightradius="5DP"
- android:bottomleftradius="30DP"
- android:bottomrightradius="30DP"/>
- <!--This is translucent and can also be set to full transparency, which is the effect of the white border--
- <solid android:color="#ff065e8d" />
- <stroke
- android:dashgap="0DP"
- android:width="4DP"
- android:color="@android: Color/white" />
- </shape>
Another: Attach a color into the drawing, need to be consulted: http://blog.sina.com.cn/s/blog_684a1d160100umuq.html reprint Please specify: rflyee_: http://blog.csdn.net/ rflyee/article/details/20785495
Detailed use of Android shape and common effects (gradient, split line, border, translucent shadow effect, etc.)