Android 引导页浮层挖洞

论坛 期权论坛 脚本     
匿名技术用户   2020-12-23 12:13   33   0

用户第一次进入应用需要显示引导,有的按钮位置由于分辨率不同,没法简单的用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图层上。

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP