Issue
I want to have a background drawable like below picture. How should I create it?
Solution
You can extends target Drawable
class(maybe ColorDrawable
). Then draw a trapezoid Path
in draw(Canvas)
methods. Adjust Paint
's alpha and color to change the effect. Code may like bellow:
public class SDrawable extends ColorDrawable {
private Path mPath = new Path();
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
public SDrawable() {
init();
}
public SDrawable(int color) {
super(color);
init();
}
private void init(){
mPaint.setColor(0x33ffffff);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
mPath.reset();
mPath.moveTo(0,0);
mPath.lineTo(canvas.getWidth()/2+50, 0);
mPath.lineTo(canvas.getWidth()/2, canvas.getHeight());
mPath.lineTo(0, canvas.getHeight());
mPath.lineTo(0, 0);
canvas.drawPath(mPath, mPaint);
}
}
Answered By - Lym Zoy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.