465_画出部分透明的蒙版
来源:互联网 发布:c语言三元表达式 编辑:程序博客网 时间:2024/05/18 08:40
画出部分透明的蒙版
public class PartialTransparentView extends View {
private Paint paint;
private Paint whitePaint;
private int screenWidth;
private int screenHeight;
private int dp1;
private int dp2;
private int dp3;
private int dp4;
private int dp5;
private int dp6;
private int dp7;
private int dp8;
private int dp9;
private int dp10;
private int dp11;
private int dp12;
private int dp20;
private int dp23;
//1.椭圆
//2.条形
//3.圆角矩形
private int type = 1;
public PartialTransparentView(Context context) {
super(context);
initView(context);
}
public PartialTransparentView(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PartialTransparentView);
type = ta.getInteger(R.styleable.PartialTransparentView_type, 1);
ta.recycle();
}
public PartialTransparentView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context);
}
private void initView(Context context) {
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(context.getResources().getColor(R.color.color_single_99000000));
whitePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
whitePaint.setColor(Color.WHITE);
whitePaint.setMaskFilter(new BlurMaskFilter(5, BlurMaskFilter.Blur.NORMAL));
whitePaint.setStyle(Paint.Style.STROKE);
whitePaint.setStrokeWidth(5);
screenWidth = DensityUtil.getScreenWidth(context);
screenHeight = DensityUtil.getScreenHeight(context);
dp1 = DensityUtil.dip2px(context, 60);
dp2 = DensityUtil.dip2px(context, 380);
dp4 = DensityUtil.dip2px(context, 540);
dp5 = DensityUtil.dip2px(context, 6);
dp6 = DensityUtil.dip2px(context, 2);
dp7 = DensityUtil.dip2px(context, 180);
dp8 = DensityUtil.dip2px(context, 48);
dp9 = DensityUtil.dip2px(context, 12);
dp10 = DensityUtil.dip2px(context, 300);
dp11 = DensityUtil.dip2px(context, 180);
dp12 = DensityUtil.dip2px(context, 430);
dp20 = DensityUtil.dip2px(context, 20);
dp23 = DensityUtil.dip2px(context, 23);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int layerId = canvas.saveLayer(0, 0, screenWidth, screenHeight, null, Canvas.ALL_SAVE_FLAG);
canvas.drawRect(0, 0, screenWidth, screenHeight, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
if (type == 1) {
RectF localRectF = new RectF(
dp1,
dp2,
screenWidth - dp1,
dp4);
canvas.drawOval(localRectF, paint);
paint.setXfermode(null);
canvas.restoreToCount(layerId);
canvas.drawOval(localRectF, whitePaint);
} else if (type == 2) {
RectF localRectF = new RectF(
dp5,
dp6,
dp7,
dp8);
canvas.drawRoundRect(localRectF, dp23, dp23, paint);
paint.setXfermode(null);
canvas.restoreToCount(layerId);
canvas.drawRoundRect(localRectF, dp23, dp23, whitePaint);
} else if (type == 3) {
RectF localRectF = new RectF(
dp9,
dp10,
dp11,
dp12);
canvas.drawRoundRect(localRectF, dp20, dp20, paint);
paint.setXfermode(null);
canvas.restoreToCount(layerId);
canvas.drawRoundRect(localRectF, dp20, dp20, whitePaint);
} else if (type == 4) {
RectF localRectF = new RectF(
dp5,
dp6,
screenWidth - dp5,
dp8);
canvas.drawRoundRect(localRectF, dp20, dp20, paint);
paint.setXfermode(null);
canvas.restoreToCount(layerId);
canvas.drawRoundRect(localRectF, dp20, dp20, whitePaint);
}
}
public void setType(int type) {
this.type = type;
invalidate();
}
}
0 0
- 465_画出部分透明的蒙版
- 462_部分或圆形透明蒙版
- OpenGL中画出透明的效果
- 285_画出连串的进度点
- 439_画出折线图的背景
- 526_画出列表中用的连接线
- (原)J2ME:从大的透明图片画出小的透明图片的方法
- 435_画出小光点
- 436_画出圆周运动
- 鼠标按下,画出图形的主要部分
- 用BitMap画出一张图片的某一部分
- 279_自定义View画出可变数量的分割线
- 440_画出折线图上的红点
- GDI+ 双缓冲 画出来的透明图片是黑色的
- java透明图片上传,透明部分变黑的解决方案。
- matlab画出的图除了图之外的部分是灰色,如果去除
- 20170404_请画出OSI七层模型和TCP/IP的五层模型
- 画出来的理解
- Atitit nodejs5 nodejs6 nodejs 7.2.1 新特性attialx总结
- 463_GreenDao框架使用
- 基于Ada语言的RTEMS应用开发
- HDU 2602 Bone Collector (0-1背包)
- 464_HttpURLConnection的post
- 465_画出部分透明的蒙版
- 数学知识
- How to Extend/Reduce LVM’s (Logical Volume Management) in Linux
- 466_简略findViewById
- STM32F4读写内部FLASH【使用库函数】
- 归并排序 Java
- android存储之preference和SQLite
- 467_去掉ScrollView的边缘阴影
- 关于Windows cmd的灵异现象