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