赞
踩
用户第一次进入应用需要显示引导,有的按钮位置由于分辨率不同,没法简单的用UI扣好的图片遮盖,而且也浪费内存。
参考了大神写的文章 http://www.jianshu.com/p/5aa96683d0dc, 把引导页画在Activity的DecorView上。
但是感觉挖洞的部分写起来太麻烦,又借鉴了一些思路:
http://blog.csdn.net/iispring/article/details/50472485
代码如下:
int canvasWidth = canvas.getWidth();
int canvasHeight = canvas.getHeight();
Paint paint = new Paint();
int layerId = canvas.saveLayer(0, 0, canvasWidth, canvasHeight, null, Canvas.ALL_SAVE_FLAG);
paint.setColor(getContext().getResources().getColor(R.color.shadow));
canvas.drawRect(0, 0, canvasWidth, canvasHeight, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
canvas.drawCircle(location[0], location[1], radius, paint);
paint.setXfermode(null);
canvas.restoreToCount(layerId);
思路很简单,就是新建一个图层,在图层上画一层遮罩,然后利用setXfermode,把遮罩上面扣一个洞,最后把图层绘制到canvas图层上。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。