1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| public class MyImageView extends AppCompatImageView {
public MyImageView(Context context) { super(context); }
public MyImageView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); }
public MyImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
@Override protected void onDraw(Canvas canvas) {
int topleft = 60; int topright = 60; int bottomleft = 0; int bottomright = 0;
float width = this.getWidth(); float height = this.getHeight();
Path path = new Path(); path.moveTo(topleft,0);
path.lineTo(width - topright,0);
path.quadTo(width,0,width,topright);
path.lineTo(width,height - bottomright);
path.quadTo(width,height,width - bottomright,height);
path.lineTo(bottomright,height);
path.quadTo(0,height,0,height - bottomleft);
path.lineTo(0,topleft);
path.quadTo(0,0,topleft,0);
canvas.clipPath(path);
super.onDraw(canvas); } }
|