Quick note about learning Android Shape Drawable. It is an XML file defining a geometric shape, including colors and gradients.
Four shapes available:
- rectangle (By default)
Addtional attributes for ring
ring, we could have following additonal attributes:
android:innerRadius- Dimension. Radius for the inner part of the ring
android:innerRadiusRatio- Radius for the inner part of the ring, expressed as a ratio of the ring’s width. Overridden by
android:innerRadius. Default value is 9.
android:thickness- Dimension. Thickness of the ring.
android:thicknessRatio- Thickness of the ring, expressed as a ratio of the ring’s width. Overridden by
android:innerRadius. Default value is 3.
ndroid:useLevel- Boolean. “true” if this is used as a
LevelListDrawable. This should normally be “false” or your shape may not appear.
Properties of shape
<shape>, we could define the following properties:
<corners>(Only with rectangle)
Creates rounded corners for the shape. Applies only when the shape is a rectangle.
android:radius for all corners. Overridden for each corner by the other four attributes.
Specifies a gradient color for the shape.
android:angle- Angle for the gradient, in degrees. 0 is left to right, 90 is bottom to top. It must be a multiple of 45. Default is 0.
android:centerX- The relative X-position for the center of the gradient (0 - 1.0).
android:centerY- The relative Y-position for the center of the gradient (0 - 1.0).
android:startColor- Starting color
android:centerColor- Optional color that comes between the start and end colors
android:endColor- Ending color
android:gradientRadius- Radius for the gradient. Only applied when
android:useLevel- Boolean. “true” if this is used as a LevelListDrawable.
android:type- Type of gradient pattern to apply.
linear- A linear gradient. By default.
radial- A radial gradient. The start color is the center color.
sweep- A sweeping line gradient.
A solid color to fill the shape.
A stroke line for the shape. Could be considered as border of the shape.
android:dashWidth- Size of each dash line. Only valid if
android:dashGap- Distance between line dashes. Only valid if
Padding to apply to the containing View element (this pads the position of the View content, not the shape).
Size of the shape.
The filename is used as the resource ID.
- In Java: R.drawable.filename
- In XML: @[package:]drawable/filename