public class RoundCornerImageView extends android.support.v7.widget.AppCompatImageView {
public RoundCornerImageView(Context context) {
super(context);
}
public RoundCornerImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RoundCornerImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
Path clipPath = new Path();
int w = this.getWidth();
int h = this.getHeight();
clipPath.addRoundRect(new RectF(0, 0, w, h), w/2, h/2, Path.Direction.CW);
canvas.clipPath(clipPath);
super.onDraw(canvas);
}
}
android 圆形倒角img
最新推荐文章于 2024-04-22 01:04:51 发布
本文介绍了一个自定义的Android ImageView子类——RoundCornerImageView,该组件能够在绘制时自动应用圆角效果。通过覆写onDraw方法并使用Canvas和Path实现圆角矩形裁剪,从而为显示的图片添加圆角。

542





