[Android UI] Shape Detailed (gradientdrawable)

Source: Internet
Author: User
Tags xml attribute

Reprinted from: http://blog.csdn.net/feng88724/article/details/6398193

In the Android development process, often need to change the default style of the control, then often use a number of pictures to solve. However, this approach may require multiple images, such as a button, a model image to be clicked, and a default style image. This makes it easy to make the apk bigger.

is there any other way besides using pictures like drawable?

This time to talk about custom shape shape,Android supports the following properties shape, gradient, stroke, corners, padding,solid and so on.

Let's take a look at two examples:

<Shapexmlns:android= "Http://schemas.android.com/apk/res/android"Android:shape= "Rectangle">    <GradientAndroid:startcolor= "#FFFF0000"Android:endcolor= "#80FF00FF"Android:angle= "+" />    <paddingAndroid:left= "50DP"Android:top= "20DP"Android:right= "7DP"Android:bottom= "7DP" />    <CornersAndroid:radius= "8DP" /></Shape>

Effect:

<?XML version= "1.0" encoding= "UTF-8"?><ShapeAndroid:shape= "Rectangle"xmlns:android= "Http://schemas.android.com/apk/res/android">    <SolidAndroid:color= "#b4000000" />    <StrokeAndroid:width= "2.0dip"Android:color= "#b4ffffff"Android:dashwidth= "3.0dip"Android:dashgap= "0.0dip" />    <paddingAndroid:left= "7.0dip"Android:top= "7.0dip"Android:right= "7.0dip"Android:bottom= "7.0dip" />    <CornersAndroid:radius= "8.0dip" /></Shape>

Effect:

Summarize all of the child properties of shape,

Single Description:

gradient--corresponds to the color gradient. StartColor, EndColor will not say much. android:angle refers to the angle from which the change begins.

Solid--fill.

Stroke-- strokes.

Corners-rounded corners.

Padding-defines how far the content is from the boundary. With Android:padding_left,android:padding_right These are a reason.

------------------------------------------------------------------

These are not the main points of the story. The focus of this lecture is on the attributes in these XML, their correspondence to the Java classes, and how to use Java classes to write the same effect!

First Look at the correspondence relationship:

In the official API introduction:

Shapedrawable:this object can be defined in an XML <shape> file with the element (this object may be defined in XML files with the <shape> element)

Gradientdrawable:this object can be defined in an XML <shape> file with the element (this object may be defined in XML files with the <shape> element)

[Parent node] shape--shapedrawable

[Sub-node] gradient--

[Sub-node] padding--

[child node] Corners-- Setcornerradius ,setcornerradii

[Child node] solid--

[Child node] stroke-- Setstroke

[child node] size--setSize

The attachment provides a summary of the classes under the android.graphics.drawable.Drawable package. Includes the corresponding relationship of the class to the XML attribute. I feel very good! You can study it if you need it.

: http://download.csdn.net/source/3251635

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.