首先在android中启动Tutorial - 用片段显示案例视图

时间:2015-03-16 07:10:07

标签: android android-fragments showcaseview

经过大量搜索后,我找到了一个很好的repository on Github来展示我想要的东西,但问题是我在我的应用程序中使用了片段而且我不知道如何使用库!在我的第一次尝试中,它给了我以下错误

 "java.lang.IllegalArgumentException: width and height must be > 0"

我找到了一个解决方案HERE,但现在它没有显示某些东西。(事实上,演示屏幕没有显示)可以提供一段可以正常处理片段的代码吗?或者帮我解决这个问题?

感谢。

1 个答案:

答案 0 :(得分:1)

嘿,男人为你做了一个样本here

我确实没有使用onCreateView中的库 它工作了

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        new ShowcaseView.Builder(getActivity())
                .setTarget(new ActionViewTarget(getActivity(), ActionViewTarget.Type.HOME))
                .setContentTitle("ShowcaseView")
                .setContentText("This is highlighting the Home button")
                .hideOnTouchOutside()
                .build();
        return rootView;
    }

评论中的问题更新

只需在onActivityCreated方法上添加代码,请检查sample created

public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        if (savedInstanceState==null){
            View view = getActivity().findViewById(R.id.hometxv);
            view.post(new Runnable() {
                @Override
                public void run() {
                    if (isAdded()) {
                        ShowcaseView sv;
                        ViewTarget target=new ViewTarget(R.id.hometxv,getActivity());
                        RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                        lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                        int margin = ((Number) (getResources().getDisplayMetrics().density * 12)).intValue();
                        lps.setMargins(margin, margin, margin, margin);

                        sv = new ShowcaseView.Builder(getActivity(), true)
                                .setTarget(target)
                                .setContentTitle("hold up")
                                .setContentText("smoke weed everyday")
                                .setShowcaseEventListener(new OnShowcaseEventListener() {
                                    @Override
                                    public void onShowcaseViewHide(ShowcaseView showcaseView) {

                                    }

                                    @Override
                                    public void onShowcaseViewDidHide(ShowcaseView showcaseView) {

                                    }

                                    @Override
                                    public void onShowcaseViewShow(ShowcaseView showcaseView) {

                                    }
                                })
                                .build();
                        sv.setButtonPosition(lps);
                    }
                }
            });
        }
    }

享受:D