binIoter / GuideView

东半球最好用的新手引导库,能够快速为任何一个View创建一个遮罩层,支持单个页面,多个引导串联展示,支持为高亮区域设置不同的图形,支持引导动画,方便扩展,良好支持fragment
3.96k stars 651 forks source link

AppCompatDialogFragment 做的弹窗,在弹窗里的一个view上做guide,显示位置不正确,包括高亮部分 #54

Open zouxianbincc opened 5 years ago

zouxianbincc commented 5 years ago

AppCompatDialogFragment 做的弹窗, 在弹窗里的一个view上做guide, 显示位置不正确,包括高亮部分。 无法正确显示在指定的view上

binIoter commented 5 years ago

方便贴一下调用代码吗?

zouxianbincc commented 5 years ago
public static void openStore(Activity activity, View view) {

    view.post(new Runnable() {
        @Override
        public void run() {
            GuideBuilder builder = new GuideBuilder();
            builder.setTargetView(view)
                    .setAlpha(156)
                    .setHighTargetCorner(20)
                    .setHighTargetPadding(10);
            builder.setOnVisibilityChangedListener(new GuideBuilder.OnVisibilityChangedListener() {
                @Override
                public void onShown() {
                }

                @Override
                public void onDismiss() {
                    isOpenShutStoreDialog(activity, false);
                }
            });
            builder.addComponent(new Component() {
                @Override
                public View getView(LayoutInflater inflater) {
                    LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.layout_guide_store, null);
                    ll.setGravity(Gravity.RIGHT);
                    TextView tv = ll.findViewById(R.id.tv);
                    ImageView iv = ll.findViewById(R.id.iv);
                    iv.setImageResource(R.mipmap.down_top);
                    tv.setText("点击这里进行 \"开店/关店\" 操作");
                    return ll;
                }

                @Override
                public int getAnchor() {
                    return ANCHOR_OVER;
                }

                @Override
                public int getFitPosition() {
                    return FIT_CENTER;
                }

                @Override
                public int getXOffset() {
                    return 0;
                }

                @Override
                public int getYOffset() {
                    return 0;
                }
            });
            Guide guide = builder.createGuide();
            guide.show(activity);
        }
    });

}

弹出dialog SysDialogFragment 是继承AppCOmpatDialogFragment public static void isOpenShutStoreDialog(Activity activity, boolean shopState) {

    String msg = shopState ? "是否确定关闭门店?" : "是否确定开启门店?";

    final SysDialogFragment syDialogFragment = new SysDialogFragment();
    syDialogFragment.setTitleText("提示")
            .setMesssageText(msg)
            .setMesssageTextSize(16f)
            .setMesssageTextColor(R.color.black)
            .setCancelTextColor(R.color.black)//默认#68c81c,在xml中设置
            .setCancelTextSize(16f)//默认14sp,在xml中设置
            .setCancelBtn("是", new View.OnClickListener() {
                @Override
                public void onClick(View v) {//默认文字为“取消”,在xml中设置
                    syDialogFragment.dismiss();

                }
            })
            .setConfirmTextColor(R.color.black)//默认#68c81c,在xml中设置
            .setConfirmTextSize(16f)//默认14sp,在xml中设置
            .setConfirmBtn("否", new View.OnClickListener() {
                @Override
                public void onClick(View v) {//默认文字为“确定”,在xml中设置
                    syDialogFragment.dismiss();
                }
            })
            .showDialog(((AppActivity) activity).getSupportFragmentManager());
}

public class SysDialogFragment extends SyDialogFragment {

boolean shopState;

@Override
protected void initData() {
    super.initData();

}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (shopState){
        StoreStatusGuide.isShutStore(getActivity(),mBtnConfirm);
    }else {
        StoreStatusGuide.isOpenStore(getActivity(),mBtnConfirm);
    }
}

}

zouxianbincc commented 5 years ago

弹窗里的view 调用蒙层 public static void isOpenStore(Activity activity, View view) {

    view.post(new Runnable() {
        @Override
        public void run() {
            GuideBuilder builder = new GuideBuilder();
            builder.setTargetView(view)
                    .setAlpha(156)
                    .setHighTargetCorner(20)
                    .setHighTargetPadding(10);
            builder.setOnVisibilityChangedListener(new GuideBuilder.OnVisibilityChangedListener() {
                @Override
                public void onShown() {
                }

                @Override
                public void onDismiss() {
                    isOpenShutStoreDialog(activity, true);
                }
            });
            TopRightComponent topRightComponent = new TopRightComponent();
            topRightComponent.setContent("点击 \"是\" 进行确认 \"开店\" ");
            topRightComponent.setPicture(R.mipmap.down_bottom);
            topRightComponent.setAnchor(Component.ANCHOR_TOP);
            builder.addComponent(topRightComponent);
            Guide guide = builder.createGuide();
            guide.show(activity);
        }
    });

}

public static void isShutStore(Activity activity, View view) {

    GuideBuilder builder = new GuideBuilder();
    builder.setTargetView(view)
            .setAlpha(156)
            .setHighTargetCorner(20)
            .setHighTargetPadding(10);
    builder.setOnVisibilityChangedListener(new GuideBuilder.OnVisibilityChangedListener() {
        @Override
        public void onShown() {
        }

        @Override
        public void onDismiss() {

        }
    });
    TopRightComponent topRightComponent = new TopRightComponent();
    topRightComponent.setContent("点击 \"是\" 进行确认 \"关店\" ");
    topRightComponent.setPicture(R.mipmap.down_bottom);
    topRightComponent.setAnchor(Component.ANCHOR_TOP);
    builder.addComponent(topRightComponent);
    Guide guide = builder.createGuide();
    guide.show(activity);

}
zouxianbincc commented 5 years ago

image

binIoter commented 5 years ago

onActivityCreated 时你的fragment还没有attach在屏幕上,虽然你post到了下一个消息循环,但是并不能保证此时fragment已经attach到屏幕上了,你可以试试postdelay 500ms或者监听viewtreeobserver.ongloballayoutlistener 里处理,试一下

zouxianbincc commented 5 years ago

postdelay 测试 无效 mBtnConfirm.getViewTreeObserver().addOnGlobalLayoutListener 测试 无效 最终这两种方案,还是不能解决

sxhdroid commented 5 years ago

我定义了一个基类,在基类的fragment中这样操作:

protected void onGlobalLayout(){

    }

    @Override
    public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                NewBasePresenterFragment.this.onGlobalLayout();
            }
        });
    }

然后在子类的onGlobalLayout()方法中调用设置蒙板可以实现

@Override
    protected void onGlobalLayout() {
        showGuideView(ivVoice);
    }
easy-money-5 commented 1 year ago

怎么展示在 dialog 里