Android图片圆角 用简单的方法实现
16lz
2021-12-22
package com.example.ysmb.myapplication;import android.content.Context;import android.graphics.Canvas;import android.graphics.Path;import android.graphics.RectF;import android.graphics.Region;import android.util.AttributeSet;import android.widget.ImageView;/** * Created by YSMB on 2016/2/16. */ public class RoundImageView extends ImageView { private Path mPath; public RoundImageView(Context context) { super(context); init(context); } public RoundImageView(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public RoundImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); } private void init(Context context) { mPath = new Path(); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); } @Override protected void onDraw(Canvas canvas) { mPath.addRoundRect(new RectF(0, 0, getWidth(), getHeight()), 50, 50, Path.Direction.CW); canvas.save(); canvas.clipPath(mPath); //这一行代码是为了去掉底部两个圆角 canvas.clipRect(new RectF(0, getHeight() / 2, getWidth(), getHeight()), Region.Op.UNION); super.onDraw(canvas); canvas.restore(); }}
更多相关文章
- Android网格布局实现--recyclerview
- Android: ViewPager and Fragments
- Android(安卓)代码混淆异常 transformClassesAndResourcesWithPr
- Android动态刷新listview中的数据
- android 异步图片处理 工具类
- android中隐藏以及显示软键盘代码
- Android(安卓)Spinner控件的简单应用
- 调用android系统自带功能
- 关于android的des算法代码