当前位置: 代码迷 >> 综合 >> Android 圆角ImageView
  详细解决方案

Android 圆角ImageView

热度:12   发布时间:2023-10-23 14:45:21.0
public class RoundCornerImageView extends ImageView {
   
 //这里是上边两个角是圆角 ,总共八个参数,后面四个决定了下面两个角的radiusstatic final float[] f ={30f,30f,30f,30f,0f,0f,0f,0f};public RoundCornerImageView(Context context) {super(context);}public RoundCornerImageView(Context context, AttributeSet attrs) {super(context, attrs);}public RoundCornerImageView(Context context, AttributeSet attrs,int defStyle) {super(context, attrs, defStyle);}@Overrideprotected void onDraw(Canvas canvas) {Path clipPath = new Path();int w = this.getWidth();int h = this.getHeight();clipPath.addRoundRect(new RectF(0, 0, w, h), f , Path.Direction.CW);canvas.clipPath(clipPath);super.onDraw(canvas);}
}

  相关解决方案