How to create this shape programmatically?
If what you want is just a simple rounded rectangle, cut the long story short.
float r=8;
ShapeDrawable shape = new ShapeDrawable (new RoundRectShape(new float[] { r, r, r, r, r, r, r, r },null,null));
shape.getPaint().setColor(Color.RED);
view.setBackground(shape);
RoundRectShape
specifies an outer (round) rect and an optional inner (round) rect.
// RoundRectShape constructor
RoundRectShape(float[] outerRadii,
RectF inset,
float[] innerRadii);
For example:
inset is a RectF that specifies the distance from the inner rect to each side of the outer rect. For no inner, pass null.
innerRadii is an array of 8 radius values, for the inner roundrect. The first two floats are for the top-left corner (remaining pairs correspond clockwise). For no rounded corners on the inner rectangle, pass null. If inset parameter is null, this parameter is ignored.
For example:
ShapeDrawable shape = new ShapeDrawable(
new RoundRectShape(
new float[]{20, 20, 20, 20, 20, 20, 20, 20},
new RectF(10, 20, 10, 20),
new float[]{40, 40, 40, 40, 40, 40, 40, 40}));