Shadow effect for graphic in Android (Shadow-effect-with-custom-shapes)

Source: Internet
Author: User

Ideas:

Add one or more layers to the custom shape and stagger to show the shadow effect. To add three-dimensional sense, when the button is pressed, only one layer is set. we can control the direction and size of shadows by using top, bottom, right and left four parameters.


Relationship Diagram

The following two shadow effects are customized:

Res/drawable-hdpi/shadow1.xml

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:state_pressed=" true "> <layer-list> <item android:le                    ft= "4DP" android:top= "4DP" ><shape> <solid android:color= "#ff58bb52"/> <corners android:radius= "30dip"/> </shape></item> </layer-list> </i Tem> <item> <layer-list> <!--first Floor--<item android:left= "4DP" and roid:top= "4DP" ><shape> <solid android:color= "#66000000"/> <corner S android:radius= "30dip"/> <!--stroke--<stroke android:width= "1DP" Android Oid:color= "#ffffffff"/> </shape></item> <!--second Floor--<item a Ndroid:bottom= "4DP" android:right= "4DP"><shape> <solid android:color= "#ff58bb52"/> <corners Android:radi us= "30dip"/> <!--strokes--<stroke android:width= "1DP" android:color= "#ff Ffffff "/> </shape></item> </layer-list></item></selector>

/testaa/res/drawable-hdpi/shadow2.xml

<?xml version= "1.0" encoding= "Utf-8"? ><selector xmlns:android= "http://schemas.android.com/apk/res/ Android > <!--click <item android:state_pressed= "true" > <layer-list> <                    Item android:left= "4DP" android:top= "4DP" > <shape>                         <solid android:color= "#ff58bb52"/> <corners android:radius= "3DP"/> </shape> </item> </layer-list></item&    Gt                 <!--Normal--<item> <layer-list> <!--first Floor--<item                         android:left= "2DP" android:top= "2DP" > <shape> <solid Android:color= "#66000000"/> <corners Android:radiu s= "3DP"/> </shape> </item> <!--second Floor--<item android:bottom= "4DP                         "Android:right=" 4DP > <shape> <solid                Android:color= "#ff58bb52"/> <corners android:radius= "3DP"/> </shape> </item> <!--third tier--<item Android                         : bottom= "6DP" android:right= "6DP" > <shape> <solid Android:color= "#ffcccccc"/> <corners android:radius= "3DP" /> </shape> </item> </layer-list> </item></selector>


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.