自定义圆角
来源:互联网 发布:微信看不到淘宝链接 编辑:程序博客网 时间:2024/05/21 07:54
package test.bwie.com.yuanjiao;import android.content.Context;import android.graphics.Bitmap;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.PorterDuff;import android.graphics.PorterDuffXfermode;import android.graphics.Rect;import android.graphics.drawable.BitmapDrawable;import android.graphics.drawable.Drawable;import android.support.annotation.Nullable;import android.util.AttributeSet;import android.widget.ImageView;/** * Created by Shinelon on 2017/12/1. */public class XCRoundImageView extends ImageView{ private Paint paint; public XCRoundImageView(Context context) { super(context,null); } public XCRoundImageView(Context context, @Nullable AttributeSet attrs) { super(context, attrs,0); } public XCRoundImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); paint = new Paint(); } @Override protected void onDraw(Canvas canvas) { Drawable drawable = getDrawable(); if (null != drawable) { Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); Bitmap b = getCircleBitmap(bitmap, 14); final Rect rectSrc = new Rect(0, 0, b.getWidth(), b.getHeight()); final Rect rectDest = new Rect(0,0,getWidth(),getHeight()); paint.reset(); canvas.drawBitmap(b, rectSrc, rectDest, paint); } else { super.onDraw(canvas); } } private Bitmap getCircleBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); int x = bitmap.getWidth(); canvas.drawCircle(x / 2, x / 2, x / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }}
//布局文件中
<test.bwie.com.yuanjiao.RoundAngleImageView android:layout_width="100dp" android:layout_height="100dp" android:layout_centerInParent="true" android:layout_marginLeft="2dp" app:roundWidth="30dp" app:roundHeight="30dp" android:id="@+id/yj" android:background="#0f0" />
阅读全文
0 0
- 自定义圆角
- 自定义圆角ImageView
- 自定义圆角dialog
- 自定义圆角控件
- 自定义圆角
- 自定义圆角按钮
- CAShapeLayer 自定义圆角
- 自定义圆角
- 自定义圆角ImageVIew
- 自定义圆角Dialog
- 自定义圆角TextView
- 自定义圆角button
- 自定义圆角ImageView
- 自定义圆角边框
- 自定义圆角ImageView
- 自定义圆角
- 自定义圆角dialog
- Android 自定义圆角图片
- 有点小开心!
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">是什么意思?
- Unity中修改相机各个Layer的照射视距
- 算法导论:c++快速排序
- Scala语言入门之环境配置
- 自定义圆角
- fabric.js图片圆角方法(测试)
- CodeForces
- Hibernate的学习之路十四(事务)
- Spring Cloud学习笔记4——服务容错保护Hystrix
- AI GOD:1013: 小英的咖啡厅
- window下面使用protobuf
- Haskell语言学习笔记(45)Profunctor
- NBUT 1619