1.创建自定义view类
@SuppressLint("AppCompatCustomView")
public class Custom_show extends ImageView {
private Paint paint;
public Custom_show(Context context) {
super(context);
}
public Custom_show(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public Custom_show(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Drawable drawable = getDrawable();
if (drawable != null) {
Bitmap bitmap = getCircleBitmap(((BitmapDrawable)drawable).getBitmap());
canvas.drawBitmap(bitmap,0,0,paint);
} else {
super.onDraw(canvas);
}
}
private Bitmap getCircleBitmap(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getH