drawable详解

1:ClipDrawable 实现progress效果。

如上图所示:

    代码十分简单首先在drawable中创建文件,标签为clip;

    这里的progress文件可随意换图片,我是写了个样式

    

最后上实现的代码

    

2:重写drawable实现圆角图片

 
 


    public RoundImageDrawable(Bitmap bitmap,float radius) {
        this.radius=radius;
        this.bitmap = bitmap;
//        CLAMP 拉伸 (设置matrix)
//        REPEAT 重复  横向、纵向不断重复这个bitmap
//        MIRROR 镜像
        BitmapShader bitmapShader=new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        mpaint=new Paint();
        mpaint.setAntiAlias(true);
        mpaint.setShader(bitmapShader);
    }


    @Override
    public void setBounds(int left, int top, int right, int bottom) {
        super.setBounds(left, top, right, bottom);
        rectF=new RectF(left,top,right,bottom);

    }

     

3重写drawable实现圆形图片

 public CircleDrawable(Bitmap bitmap) {
        this.bitmap = bitmap;

        BitmapShader bitmapShader=new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        paint=new Paint();
        paint.setAntiAlias(true);
        paint.setShader(bitmapShader);
        size=Math.min(bitmap.getWidth(),bitmap.getHeight());
        cx=size/2;
        cy=size/2;
        radius=size/2;
    }


    @Override
    public void draw(Canvas canvas) {
        canvas.drawCircle(cx,cy,radius,paint);
    }

 github地址






 
 


    

猜你喜欢

转载自blog.csdn.net/qq_23025319/article/details/79629780
今日推荐