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

Source: Internet
Author: User

Ideas:

Add one or more layers in your own definition shape. and staggered. You can display the shadow effect. To add three-dimensional sense, the button presses, setting only one layer. we can control the direction and size of the shadows by using top, bottom, right and left four parameters.


Relationship Diagram

Here you define two shadow effects:

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>


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

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.