Android 图片圆角的简单方法

package com.jereh.helloworld.activity.ui;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
 * Created by Hh。 on 2016/10/31.
 */
public class UIImageView extends ImageView {
    public UIImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public UIImageView(Context context) {
        super(context);
    }
    public UIImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
    }
    @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), 30.0f, 30.0f, Path.Direction.CW);
        canvas.clipPath(clipPath);
        super.onDraw(canvas);
    }
}

  

posted @ 2016-10-31 14:43  八十年代的金坛县  阅读(218)  评论(0编辑  收藏  举报