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="http://schemas.android.com/apk/res/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="http://schemas.android.com/apk/res/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