Use Layer-list to write shadow effects in Android

Source: Internet
Author: User

There are a number of ways to achieve this effect, such as a background image that directly casts a shadow effect, or a code to draw one (OnDraw ()). This time we use layer-list directly to achieve. Create an XML in the project res->drawable, if there is layer-list selection in the list, select Create directly, if not, then feel free (it seems that there is no layer-list selection below 4.0), If not, change the root tag in the XML file to Layer-list. The specific code for the above effect is as follows:

<?XML version= "1.0" encoding= "Utf-8"?><layer-listxmlns:android= "Http://schemas.android.com/apk/res/android" >     <!--shaded Section -    <!--a person feels more expressive: top represents the height of the shadow below, and left represents the width of the shadow on the right. In fact, the corresponding offset,solid color is the color of the shadow, you can set the angle and so on -    <ItemAndroid:left= "2DP"Android:top= "2DP">        <ShapeAndroid:shape= "Rectangle" >             <GradientAndroid:angle= "+"Android:endcolor= "#0F000000"Android:startcolor= "#0F000000" />             <CornersAndroid:bottomleftradius= "6dip"Android:bottomrightradius= "6dip"Android:topleftradius= "6dip"Android:toprightradius= "6dip" />        </Shape>    </Item>     <!--Background Section -    <!--the expression of the image: The bottom represents the background part at the top edge beyond the height of the shadow, right represents the background part on the left beyond the width of the shadow (corresponding offset) -    <ItemAndroid:bottom= "3DP"Android:right= "3DP">        <ShapeAndroid:shape= "Rectangle" >             <GradientAndroid:angle= "+"Android:endcolor= "#FFFFFF"Android:startcolor= "#FFFFFF" />             <CornersAndroid:bottomleftradius= "6dip"Android:bottomrightradius= "6dip"Android:topleftradius= "6dip"Android:toprightradius= "6dip" />        </Shape>    </Item>

Use Layer-list to write shadow effects in Android

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.