Detailed use of Android shape and common effects (gradient, split line, border, translucent shadow effect, etc.)

Source: Internet
Author: User

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:scaleTypeTo "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
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="Rectangle" >
  4. <corners android:radius="16DP" />
  5. <!--This is translucent and can also be set to full transparency, which is the effect of the white border--
  6. <solid android:color="#80065e8d" />
  7. <stroke
  8. android:dashgap="0DP"
  9. android:width="4DP"
  10. android:color="@android: Color/white" />
  11. </shape>
3. Split Line effect: [HTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="line" >
  4. <stroke
  5. android:width="4DP"
  6. android:color="@android: Color/black" />
  7. </shape>
If: 4, unilateral angle effect [HTML]View Plaincopy
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <shape android:shape="Rectangle" xmlns:android= "http://schemas.android.com/apk/res/ Android ">
  3. <Corners
  4. android:topleftradius="5DP"
  5. android:toprightradius="5DP"
  6. android:bottomleftradius="30DP"
  7. android:bottomrightradius="30DP"/>
  8. <!--This is translucent and can also be set to full transparency, which is the effect of the white border--
  9. <solid android:color="#ff065e8d" />
  10. <stroke
  11. android:dashgap="0DP"
  12. android:width="4DP"
  13. android:color="@android: Color/white" />
  14. </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.)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.