1.新建一个RoundImage.java文件
package com.jhg.freshman;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.ImageView;
public class RoundImageView extends android.support.v7.widget.AppCompatImageView {
/**
* 圆形模式
*/
private static final int MODE_CIRCLE = 1;
/**
* 普通模式
*/
private static final int MODE_NONE = 0;
/**
* 圆角模式
*/
private static final int MODE_ROUND = 2;
private Paint mPaint;
private int currMode = 0;
/**
* 圆角半径
*/
private int currRound = dp2px(10);
public RoundImageView(Context context) {
super(context);
initViews();
}
public RoundImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public RoundImageView(Context context, AttributeSet attrs, int defStyleAttr) {