时间:2021-05-21
废话不多说了,直接给大家贴代码了,具体代码如下所示:
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);}}好了,有关Android 圆角 ImageView类可设置弧度的内容小编就给大家介绍到这里,希望对大家有所帮助!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了android中圆角图像生成方法。分享给大家供大家参考。具体分析如下:在android开发中为了美观,常常要求ImageView中显示出圆角图像的
android中的ImageView只能显示矩形的图片,这样一来不能满足我们其他的需求,比如要显示圆角矩形的图片,这个时候,我们就需要自定义ImageView了
ImageView设置手指滑动缩放效果,具体实现步骤大家通过本文学习下吧!实现步骤1,imageview设置scaletype为android:scaleTyp
首先我将贴出几种实现圆角边框的dmeo程序效果图:方式一:使用shape元素填充背景,设置圆角/带弧度的角1、首先在\res\drawable下新建Shape为
很多android应用都用到了圆角头像,或者一些圆角图片处理起来比较麻烦,直接上圆角图片工具类publicclassCircleImageViewextends