Android Learning-shape

Source: Internet
Author: User
Tags set background

Shape drawable
An XML file that defines a geometric shape, including colors and gradients. A geometry-defined XML document that includes colors and gradients.

Brief introduction  

Role: Geometric shapes defined in XML

Location: Name of the res/drawable/file. xml

The method used:

Java code: r.drawable. Name of the file

Layout: android:background= "@drawable/File name"

Property

<shape> android:shape=["Rectangle" | "Oval" | "Line" | "Ring"]

of which, Rectagle: Rectangle, Oval: Ellipse, line: Horizontal straight, ring: ring

Child elements  

  <corners>: Specify the radius of the corner, simply put, the larger the value of the more rounded, the smaller the value is closer to the right angle, the parameters are:

1. android:radius= "integer"

2. android:topleftradius= "integer" <!--upper left corner--

3. android:toprightradius= "integer" <!--top-right corner

4. android:bottomleftradius= "integer" <!--lower right corner--

5. android:bottomrightradius= "integer" <!--lower left corner--

The Android:radius directly specifies the radius of the 4 corners, and the other 4 properties can be set individually

  <gradient>: Set color gradients    

 1. android:angle= "integer" To set the angle of the gradient, the value must be a multiple of 45, the default is 0, that is, from left to right gradient.   A value of 90 o'clock, a gradient from bottom to top, and so on with a value of 180, a gradient from right to left , and a gradient from top to bottom at 270.

2. android:centerx= the horizontal center point of the "integer" gradient with a value of 0-1.0

3. android:centery= the vertical center point of the "integer" gradient with a value of 0-1.0

4. Android:centercolor= Color of "integer" Center, not required

5. android:startcolor= color when "color" starts to fade

6. android:endcolor= color when "color" ends a gradient

7. android:gradientradius= the radius of the "integer" Gradient for android:type= "radial" only; (radial gradient requires a radius specified)

8. android:type=["Linear" | "Radial" | Types of "sweep"] gradients, linear, central radial, tested like a pattern of radar scanning

9. Android:useslevel=["true" | "False" appears to be used as a level-list.

<padding>: to set margins for content or sub-labels, 4 properties top, bottom, left, right, note that this tag is for the margins of the content and the view that currently applies this shape. Instead of setting the margins of the current view with the parent element.

  <SIZE>: Set Background size, width and height two properties

<solid>: There is only one attribute, color, that sets the colors of the entire background, and if the gradient is already defined, then this property is invalid;

<stroke>: stroke, that is, set border    

1. Android:width= the width of the "integer" Stroke

2. Color of the android:color= "color" stroke

3. Android:dashwidth= "integer" must be used in conjunction with the following dashgap, that is, two attributes can not use, if used, two must be used. So what's the role of the two brothers?

4. It is possible to achieve the effect of border segmentation, the former specifies the length of each paragraph the latter specifies the gap between the two ends or distance.

5. android:dashgap= "Integer"

Instance:

Let's look at the following code:
Copy to clipboard xml/html code
<shape>

<!--solid--
<solid android:color= "#ff9d77"/>

<!--gradients--

<gradient
Android:startcolor= "#ff8c00"

Android:endcolor= "#FFFFFF"

Android:angle= "/>"

<!--strokes--

<stroke
Android:width= "2DP"
Android:color= "#dcdcdc"/>

<!--rounded corners--

<corners

android:toprightradius= "20DP" upper right corner

android:bottomleftradius= "20DP" lower right corner

android:topleftradius= "1DP" upper left corner

android:bottomrightradius= "0DP" lower left corner

/>

<padding
android:left= "10DP"

android:top= "10DP"

android:right= "10DP"

android:bottom= "10DP"/>

</shape>

Android Learning-shape

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.