国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android 圓角 ImageView類可設(shè)置弧度(代碼簡單)

2020-01-02 06:59:41
字體:
供稿:網(wǎng)友

廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:

public class RoundImageView extends ImageView {private Paint paint;private int roundWidth = 50;private int roundHeight = 50;private Paint paint2;public RoundImageView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);init(context, attrs);}public RoundImageView(Context context, AttributeSet attrs) {super(context, attrs);init(context, attrs);}public void SetRoundValue(float roundValue) {roundWidth = (int) roundValue;roundHeight = (int) roundValue;}public RoundImageView(Context context) {super(context);init(context, null);}@SuppressLint("Recycle")private void init(Context context, AttributeSet attrs) {if (attrs != null) {TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundAngleImageView);roundWidth = a.getDimensionPixelSize(R.styleable.RoundAngleImageView_roundWidth, roundWidth);roundHeight = a.getDimensionPixelSize(R.styleable.RoundAngleImageView_roundHeight, roundHeight);} else {float density = context.getResources().getDisplayMetrics().density;roundWidth = (int) (roundWidth * density);roundHeight = (int) (roundHeight * density);}paint = new Paint();paint.setColor(Color.WHITE);paint.setAntiAlias(true);paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));paint2 = new Paint();paint2.setXfermode(null);}@Overridepublic void draw(Canvas canvas) {Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);Canvas canvas2 = new Canvas(bitmap);super.draw(canvas2);drawLiftUp(canvas2);drawRightUp(canvas2);drawLiftDown(canvas2);drawRightDown(canvas2);canvas.drawBitmap(bitmap, 0, 0, paint2);bitmap.recycle();bitmap = null;}private void drawLiftUp(Canvas canvas) {Path path = new Path();path.moveTo(0, roundHeight);path.lineTo(0, 0);path.lineTo(roundWidth, 0);path.arcTo(new RectF(0, 0, roundWidth * 2, roundHeight * 2), -90, -90);path.close();canvas.drawPath(path, paint);}private void drawLiftDown(Canvas canvas) {Path path = new Path();path.moveTo(0, getHeight() - roundHeight);path.lineTo(0, getHeight());path.lineTo(roundWidth, getHeight());path.arcTo(new RectF(0, getHeight() - roundHeight * 2, 0 + roundWidth * 2, getWidth()), 90, 90);path.close();canvas.drawPath(path, paint);}private void drawRightDown(Canvas canvas) {Path path = new Path();path.moveTo(getWidth() - roundWidth, getHeight());path.lineTo(getWidth(), getHeight());path.lineTo(getWidth(), getHeight() - roundHeight);path.arcTo(new RectF(getWidth() - roundWidth * 2, getHeight() - roundHeight * 2, getWidth(), getHeight()), 0,90);path.close();canvas.drawPath(path, paint);}private void drawRightUp(Canvas canvas) {Path path = new Path();path.moveTo(getWidth(), roundHeight);path.lineTo(getWidth(), 0);path.lineTo(getWidth() - roundWidth, 0);path.arcTo(new RectF(getWidth() - roundWidth * 2, 0, getWidth(), 0 + roundHeight * 2), -90, 90);path.close();canvas.drawPath(path, paint);}}

好了,有關(guān)Android 圓角 ImageView類可設(shè)置弧度的內(nèi)容小編就給大家介紹到這里,希望對(duì)大家有所幫助!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 洪洞县| 金山区| 鲁山县| 阿城市| 郓城县| 台前县| 伊宁市| 涿州市| 舞阳县| 靖州| 大邑县| 长海县| 洛阳市| 南丰县| 东明县| 石家庄市| 柘荣县| 宁晋县| 黄大仙区| 宁蒗| 商洛市| 瑞丽市| 桐乡市| 泗洪县| 镇雄县| 开化县| 宝丰县| 昌邑市| 桑日县| 理塘县| 罗甸县| 大同市| 台东县| 五原县| 阿瓦提县| 金溪县| 大冶市| 武穴市| 临朐县| 诏安县| 襄樊市|