PaintDrawablepublic class PaintDrawable extends ShapeDrawable Drawable that draws its bounds in the given paint, with optional
rounded corners. |
Constructors Summary |
---|
public PaintDrawable()
| public PaintDrawable(int color)
getPaint().setColor(color);
|
Methods Summary |
---|
protected boolean | inflateTag(java.lang.String name, android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs)
if (name.equals("corners")) {
TypedArray a = r.obtainAttributes(attrs,
com.android.internal.R.styleable.DrawableCorners);
int radius = a.getDimensionPixelSize(
com.android.internal.R.styleable.DrawableCorners_radius, 0);
setCornerRadius(radius);
// now check of they have any per-corner radii
int topLeftRadius = a.getDimensionPixelSize(
com.android.internal.R.styleable.DrawableCorners_topLeftRadius, radius);
int topRightRadius = a.getDimensionPixelSize(
com.android.internal.R.styleable.DrawableCorners_topRightRadius, radius);
int bottomLeftRadius = a.getDimensionPixelSize(
com.android.internal.R.styleable.DrawableCorners_bottomLeftRadius, radius);
int bottomRightRadius = a.getDimensionPixelSize(
com.android.internal.R.styleable.DrawableCorners_bottomRightRadius, radius);
if (topLeftRadius != radius || topRightRadius != radius ||
bottomLeftRadius != radius || bottomRightRadius != radius) {
setCornerRadii(new float[] {
topLeftRadius, topLeftRadius,
topRightRadius, topRightRadius,
bottomLeftRadius, bottomLeftRadius,
bottomRightRadius, bottomRightRadius
});
}
a.recycle();
return true;
}
return super.inflateTag(name, r, parser, attrs);
| public void | setCornerRadii(float[] radii)Specify radii for each of the 4 corners. For each corner, the array
contains 2 values, [X_radius, Y_radius]. The corners are ordered
top-left, top-right, bottom-right, bottom-left
if (radii == null) {
if (getShape() != null) {
setShape(null);
}
} else {
setShape(new RoundRectShape(radii, null, null));
}
| public void | setCornerRadius(float radius)Specify radius for the corners of the rectangle. If this is > 0, then the
drawable is drawn in a round-rectangle, rather than a rectangle.
float[] radii = null;
if (radius > 0) {
radii = new float[8];
for (int i = 0; i < 8; i++) {
radii[i] = radius;
}
}
setCornerRadii(radii);
|
|