Advertisement

RN系列之五十三:解决Android图片圆角问题的终极方案

阅读量:
复制代码
复制代码
   @Override

    
   protected void onDraw(Canvas canvas) {
    
       if (mBorderRadius > 0) {
    
     float[] rids = {mBorderRadius,mBorderRadius,mBorderRadius,mBorderRadius,mBorderRadius,mBorderRadius,mBorderRadius,mBorderRadius,};
    
     Path path = new Path();
    
     int w = this.getWidth();
    
     int h = this.getHeight();
    
     /*向路径中添加圆角矩形。radii数组定义圆角矩形的四个圆角的x,y半径。radii长度必须为8*/
    
     path.addRoundRect(new RectF(0,0,w,h),rids,Path.Direction.CW);
    
     canvas.clipPath(path);
    
       }
    
     super.onDraw(canvas);
    
   }
    
    
    

全部评论 (0)

还没有任何评论哟~