圆角ImageView
来源:互联网 发布:windows任务管理器画图 编辑:程序博客网 时间:2024/06/04 18:53
package com.example.ui;import android.R;import android.content.Context;import android.content.res.TypedArray;import android.graphics.Bitmap;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.Path;import android.graphics.PorterDuff;import android.graphics.PorterDuffXfermode;import android.graphics.RectF;import android.graphics.Bitmap.Config;import android.util.AttributeSet;import android.widget.ImageView;public class RoundAngleImageView extends ImageView { private Paint paint; private int roundWidth = 5; private int roundHeight = 5; private Paint paint2; public RoundAngleImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context, attrs); } public RoundAngleImageView(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); } public RoundAngleImageView(Context context) { super(context); init(context, null); } private void init(Context context, AttributeSet attrs) { if (attrs != null) { /*TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundAngleImageView); //代码中设置字体大小,读xml配置。 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); } @Override public 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(); } 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); } }
0 0
- 圆角ImageView
- 圆角imageview
- ImageView圆角
- ImageView圆角
- 圆角ImageView
- 圆角Imageview
- 圆角ImageView
- Android 圆角ImageView
- 圆形 圆角ImageView
- Android:圆角ImageView
- 自定义ImageView 圆角shape
- 圆角Imageview--RoundedImageView
- 处理imageView圆角
- android自定义 圆角Imageview
- Android 圆角ImageView
- 自定义View圆角ImageView
- 自定义View圆角ImageView
- ImageView
- 黑马程序员--JQuery学习笔记
- flex垃圾回收机制
- 编写更好的jQuery代码的建议
- JBoss 系列九十: 红帽发布 JBoss BPM Suite 6 最终版本
- 误删/var/lib/dpk文件夹
- 圆角ImageView
- 九度oj 题目1201:二叉排序树
- 黑马程序员--ASP.NET基础学习笔记
- OpenGL FBO 对象
- IOS开发之----常用函数和常数
- java中的闭包和回调
- IDA*算法
- 接口和抽象类
- hashtable和hashmap