前言
满足自定义蒙层颜色,裁剪区域尺寸,自定义说明布局位置,满足自己项目中所需即可,如下图展示:
实现原理
1、浮层的位置在activity的DecorView中,DecorView是FrameLayout的子类,所以整个蒙层,都是基于FrameLayout实现
代码如下:
if (anchor == null) {
anchor = activity.findViewById(android.R.id.content);
}
if (anchor instanceof FrameLayout) {
mParentView = (FrameLayout) anchor;
} else {
FrameLayout frameLayout = new FrameLayout(activity);
ViewGroup parent = (ViewGroup) anchor.getParent();
indexOfChild = parent.indexOfChild(anchor);
parent.removeView(anchor);
if (indexOfChild >= 0) {
parent.addView(frameLayout, indexOfChild, anchor.getLayoutParams());