Android Project Combat (36): Add a shadow effect to the background

Source: Internet
Author: User

Original: Android Project Combat (36): Add shadow effect to background

Rounded background You should always use:

A drawable resource file that controls corner fillets and solid fill colors

<shape xmlns:android="">    < Corners android:radius="@dimen/dp_2"></corners>    <solid android:color= " @color/standard_main "></solid></shape>

On this basis, a rounded background with shaded effect is implemented

The code is as follows

<?xml version="1.0"encoding="Utf-8"? ><layer-list xmlns:android=""><!--Shadow section--><!--personally feel 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--><Item Android:left="4DP"Android:top="4DP"> <shape android:shape="Rectangle"> <Gradient Android:angle=" the"Android:endcolor="#0F000000"Android:startcolor="#0F000000"/> <Corners Android:bottomleftradius="@dimen/dp_4"Android:bottomrightradius="@dimen/dp_14"Android:topleftradius="@dimen/dp_4"Android:toprightradius="@dimen/dp_4"/> </shape></item><!--Background part--><!--image expression: Bottom represents the background part above the height of the shadow at the top edge, Right represents the background part on the left beyond the width of the shadow (the corresponding offset)--><Item Android:bottom="3DP"Android:left="@dimen/dp_0.5"Android:top="@dimen/dp_0.5"Android:right="3DP"> <shape android:shape="Rectangle"> <Gradient Android:angle=" the"Android:endcolor="#FFFFFF"Android:startcolor="#FFFFFF"/> <Corners Android:bottomleftradius="@dimen/dp_4"Android:bottomrightradius="@dimen/dp_14"Android:topleftradius="@dimen/dp_4"Android:toprightradius="@dimen/dp_4"/> </shape></item></layer-list>

Effect: You can see a small range of gray shading effects on the right and bottom sides.

The background effect of the item as a list in the actual product:

Does it make a similar cardview effect?

Android Project Combat (36): Add a shadow effect to the background

Related Article

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: 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.