Android Gradient drawable

Source: Internet
Author: User

The gradient drawable is defined using the <gradient> tag as a child node in the shape drawable definition.

Each gradient drawable requires at least one StartColor and EndColor property, and an optional Middlecolor attribute is supported. By using the Type property, you can define a gradient as one of the following types:

Linear: This is the default gradient type, which shows a direct color transition from StartColor to EndColor, as defined by the Angle property.

Radiation: Draws a circular gradient from StartColor to EndColor from the outer boundary of the shape to the center.

Scan: Draws a sweep gradient that transitions from startcolor to endcolor along the outer bounds of the parent shape (usually a ring).

1. Create a new drawable folder under Res.

2. Create a new XML file under the Drawable folder.

3. Reference this file in the Bacground attribute of the component.

Here are the linear codes and effects:

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android"     android:shape= "Rectangle"    android:uselevel= "false"    >    <gradient         android:startcolor= " #ffffff "        android:endcolor=" #ffffff "        android:centercolor=" #000000 "        android:uselevel=" false "        Android:type= "linear"        android:angle= "/></shape>"        



Radiation gradient Ellipse

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android"     android:shape= "Oval"    android:uselevel= "false"    >    <gradient         android:type= "Radial"        android:startcolor= "#ffffff"        android:endcolor= "#ffffff"        android:centercolor= "#000000"        Android : Uselevel= "false"        android:gradientradius= "/></shape>"        



Scan gradients:

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android"     android:shape= "Ring"    android:uselevel= "false"    android:innerradiusratio= "3"    android: thicknessratio= "8"    >    <gradient         android:startcolor= "#ffffff"        android:endcolor= "#ffffff"        android:centercolor= "#000000"        android:uselevel= "false"        android:type= "sweep"        />    < /shape><!--Scan the gradient ellipse--


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.