Layer-list, which is often used in the Android UI design, is critical to shape's role in beautifying the controls.
- Shape
- Role: Defining Geometry in XML
- Property:
<shape> Android:shape=["rectangle" | "oval" | "line" | "ring"] 其中rectagle矩形,oval椭圆,line水平直线,ring环形
<?XML version= "1.0" encoding= "Utf-8"?> <Shapexmlns:android= "Http://schemas.android.com/apk/res/android"Android:shape=["Rectangle"| "Oval" | "Line" | "Ring"]> <GradientGradient Android:angle= "integer"gradient angle, 0 from left to right, 90 for bottom to top, number 45 for integer, default to 0; Android:centerx= "integer"Android:centery= "integer"Android:centercolor= "integer"Android:endcolor= "Color"End Color Android:gradientradius= "integer"Android:startcolor= "Color"Starting color Android:type=["Linear"| "Radial" | "Sweep"] gradient style liner linear gradient radial ring gradient sweep android:useslevel=["true"| "False"]/> <SolidFill
Android:color= "Color"The color of the fill/> <StrokeStroke Android:width= "integer"width of stroke android:color= "Color"the color of the stroke android:dashwidth= "integer"indicates the width of the horizontal line Android:dashgap= "integer"represents the distance between horizontal lines/> <paddingAndroid:left= "integer"Android:top= "integer"Android:right= "integer"Android:bottom= "integer" /> <Cornersrounded Corners Android:radius= "integer"the larger the radius of the fillet the greater the rounded Android:topleftradius= "integer"Top left corner radius Android:toprightradius= "integer"Top right corner radius Android:bottomleftradius= "integer"Lower left fillet corner radius Android:bottomrightradius= "integer"Corner radius of right bottom corner/> </Shape>
- Layer-list, a plurality of pictures or more than two effects in order to cascade;
<?XML version= "1.0" encoding= "Utf-8"?><layer-listxmlns:android= "Http://schemas.android.com/apk/res/android" > <ItemAndroid:id= "@android: Id/background"> <Shape> <CornersAndroid:radius= "0dip" /> <SolidAndroid:color= "#FDE5A2" /> </Shape> </Item> <ItemAndroid:id= "@android: id/secondaryprogress"> <Clip> <Shape> <CornersAndroid:radius= "0dip" /> <GradientAndroid:angle= "+"Android:centercolor= "#80ffb600"Android:centery= "0.75"Android:endcolor= "#a0ffcb00"Android:startcolor= "#80ffd300" /> </Shape> </Clip> </Item> <ItemAndroid:id= "@android: id/progress"> <Clip> <Shape> <CornersAndroid:radius= "0dip" /> <SolidAndroid:color= "#FD2702" /> </Shape> </Clip> </Item></layer-list>
Layer-list cascading styles correspond to layerdrawable in the program, using the following methods:
Resources resources =new drawable[2]; layers[0] = r.getdrawable (r.drawable.white); layers[1] =new layerdrawable (Layers) ((ImageView) Findviewbyid (R.id.imageview)). Setimagedrawable (layerdrawable);
Reference article:
http://tbwisk.github.io/lessons/2015/01/14/Android%E5%BC%80%E5%8F%91%EF%BC%8Cshape%EF%BC%8Cselector%EF%BC% 8clayer-list%e4%bb%8b%e7%bb%8d/
Android layer-list Clip shape Selector details and use