Android 圆角 ImageView类可设置弧度(代码简单)

Android 圆角 ImageView类可设置弧度(代码简单),第1张

概述废话不多说了,直接给大家贴代码了,具体代码如下所示:publicclassRoundImageViewextendsImageView{

废话不多说了,直接给大家贴代码了,具体代码如下所示:

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,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,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() - roundHeight);path.arcTo(new RectF(getWIDth() - rounDWIDth * 2,getWIDth(),getHeight()),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 + roundHeight * 2),paint);}}

好了,有关AndroID 圆角 ImageVIEw类可设置弧度的内容小编就给大家介绍到这里,希望对大家有所帮助!

总结

以上是内存溢出为你收集整理的Android 圆角 ImageView类可设置弧度(代码简单)全部内容,希望文章能够帮你解决Android 圆角 ImageView类可设置弧度(代码简单)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1141554.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存