This article shares the specific content of drawable using Shape resources for your reference. The specific content is as follows
1. Draw aDotted line in horizontal direction
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:andro android:shape="line" > <stroke android:dashGap="3dp" android:dashWidth="6dp" android:width="1dp" android:color="#FF8C69" /> </shape>
Android:width=”1dp” is the height of the line
android:dashGap=”3dp” represents the width of the gap between the dotted lines, and 0 represents a solid line;
android:dashWidth=”6dp” indicates the width of each dotted line.
Note: In version 4.0 or above, you need to set android:layerType="software" in the control, otherwise the dotted line is invalid and will be displayed as a solid line.
2. Draw aDotted lines in the vertical direction
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:andro android:fromDegrees="90" android:toDegrees="90" android:drawable="@drawable/line" > </rotate>
Or use the following method
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:andro android:fromDegrees="90" android:toDegrees="90" > <shape android:shape="line" > <stroke android:dashGap="3px" android:dashWidth="6px" android:width="1dp" android:color="#FF8C69" /> </shape> </rotate>
3. Draw oneSolid circle
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:andro android:shape="oval" > <solid android:color="#FF8C69" /> </shape>
4. Draw oneCircle
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:andro android:innerRadius="15dp" android:shape="ring" android:thickness="10dp" android:useLevel="false" > <solid android:color="#FF8C69" /> <stroke android:width="1dp" android:color="#FF8C69" /> </shape>
android:innerRadius=”15dp” Set the dimensions, the radius of the inner ring
android:thickness=”10dp” Set the size, the thickness of the ring
android:useLevel=”false” boolean value, if used as LevelListDrawable, the value is true, otherwise it is false.
android:innerRadiusRatio=”9” floating point type, the width ratio of the ring represents the radius of the inner ring, indicating that the radius of the inner ring is equal to the width of the ring divided by 5. This value can be overwritten, and the default is 9.
android:thicknessRatio=”2” floating point type, the thickness of the ring is expressed in the width ratio of the ring, indicating that the thickness of the ring is equal to the width of the ring divided by 2. This value can be overwritten by android:thickness, and the default value is 3.
5. Draw onerectangle
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:andro android:shape="rectangle" > <corners android:radius="30dp" /> <solid android:color="#FF8C69" /> <stroke android:width="1dp" android:color="#FF8C69" /> </shape>
Summarize
<?xml version="1.0" encoding="utf-8"?> <!-- shape drawable xmlA geometric shape defined in the file,Defined inres/drawable/In the directory,file namefilenameResources called accessID Access through in code,existxmlPassed in the file@[package:]drawable/filenameMake an access。 --> <!-- android:shape=["rectangle" | "oval" | "line" | "ring"] shapeShape,Default is rectangle,Can be set as a rectangle(rectangle)、Oval(oval)、Linear shapes(line)、Circular(ring)下面的属性只有existandroid:shape="ringAvailable when: android:innerRadius size,Radius of inner ring。 android:innerRadiusRatio Floating point type,以环的宽度比率来表示Radius of inner ring,For example,ifandroid:innerRadiusRatio,Indicates that the inner ring radius is equal to the width of the ring divided by5,This value can be overwritten,Default is9. android:thickness size,The thickness of the ring android:thicknessRatio Floating point type,以环的宽度比率来表示The thickness of the ring,For example,ifandroid:thicknessRatio="2", 那么The thickness of the ring就等于环的宽度除以2。This value can beandroid:thicknessCovered,The default value is3. android:useLevel booleanvalue,ifwhen做是LevelListDrawable使用hourvalue为true,Otherwise it isfalse. --> <shape xmlns:andro android:shape="rectangle" > <!-- Round corners android:radius Integer radius android:topLeftRadius Integral upper left corner radius android:topRightRadius Integral upper right corner radius android:bottomLeftRadius Integral lower left corner radius android:bottomRightRadius Integral lower right corner radius --> <corners android:bottomLeftRadius="20dp" android:bottomRightRadius="25dp" android:radius="8dp" android:topLeftRadius="5dp" android:topRightRadius="15dp" /> <!-- Gradient color android:startColor 颜色value Starting color android:endColor 颜色value结束颜色 android:centerColor Integer Gradient Middle Color,That is, the color between the start color and the end color android:angle Integer Gradient Angle(PS:whenangle=0hour,Gradient color是从左向右。 然后逆hour针方向转,whenangle=90hour为从下往上。angleMust be45Integer times) android:type ["linear" | "radial" | "sweep"] Gradient Type(取value:linear、radial、sweep) linear Linear Gradient,This is the default setting radial Radioactive gradient,Centered on the color of the beginning。 sweep Scan line gradient。 android:useLevel ["true" | "false"]if要使用LevelListDrawableObject,It needs to be set astrue。Set astrueNo gradient。false有Gradient color android:gradientRadius 整型Gradient color半径.when android:type="radial" hour才使用。Use alone android:type="radial"Will report an error。 android:centerX Integer Gradient CenterXRelative position of point coordinates android:centerY Integer Gradient CenterYRelative position of point coordinates --> <gradient android:angle="45" android:endColor="#80FF00FF" android:startColor="#FFFF0000" /> <!-- Inner margin,That is, the distance between content and edges android:left 整型左Inner margin android:top 整型上Inner margin android:right 整型右Inner margin android:bottom 整型下Inner margin --> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> <!-- size size android:width Integer width android:height Integer height --> <size android:width="600dp" /> <!-- Internal filling android:color 颜色value填充颜色 --> <solid android:color="#ffff9d77" /> <!-- Stroke android:width 整型Stroke的宽度 android:color 颜色valueStroke的颜色 android:dashWidth 整型表示Stroke的样式是虚线的宽度, value为0hour,Expressed as solid line。value大于0It's a dotted line。 android:dashGap 整型表示Stroke为虚线hour,The spacing between dotted lines Right now“ - - - - ” --> <stroke android:width="2dp" android:color="#dcdcdc" /> </shape>
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.