您的位置:首页 > 移动开发 > Android开发

Android 图片圆角的简单方法

2017-01-20 10:02 267 查看
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);
}
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: