当前位置:   article > 正文

Android 引导页浮层挖洞_android 新手引导挖洞

android 新手引导挖洞

用户第一次进入应用需要显示引导,有的按钮位置由于分辨率不同,没法简单的用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);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

思路很简单,就是新建一个图层,在图层上画一层遮罩,然后利用setXfermode,把遮罩上面扣一个洞,最后把图层绘制到canvas图层上。

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号