I have tried to create rectangle like this, in xml with shape but no luck, is this possible or how to transparent this image, I mean it's color want to transparent like we define color for any shape with alpha then we get transparency, is there any way for 1 of this?
Thanks
I was able to do this by making the color of the clipped region (a circle in my case) same to the background color.
float[] outerR = new float[] { 12, 12, 12, 12, 0, 0, 0, 0 };
float[] circleR = new float[] { 50, 50, 50, 50, 50, 50, 50, 50 };
mDrawables = new ShapeDrawable[2]; mDrawables[0] = new ShapeDrawable(new RoundRectShape(outerR, null, null)); mDrawables[1] = new ShapeDrawable(new RoundRectShape(circleR, null, null)); mDrawables[0].getPaint().setColor(0xFF0000FF); mDrawables[1].getPaint().setColor(Color.GRAY);
And in onDraw:
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.GRAY);
int x = 10;<br>
int y = 10;<br>
int width = 100;<br>
int height = 100;
for (int i = 0; i < mDrawables.length; i++) {
Drawable dr = mDrawables[i];
if (i == 0) {
dr.setBounds(x, y, x + width, y + height);
dr.draw(canvas);
} else {
x = 10 + 75;
y = 10 + 75;
dr.setBounds(x, y, x + 50, y + 50);
dr.draw(canvas);
}
}
canvas.save();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.