短视频软件开发,动态计算在指定位置添加view,实现引导页效果

短视频软件开发,动态计算在指定位置添加view,实现引导页效果实现的相关代码

方式一:Popupwindow

private void showGuideWindowPop() {
    if (mGuideWindow == null) {
        mGuideView = (RelativeLayout) LayoutInflater.from(this)
                                          .inflate(R.layout.layout_wallet_guide, null);
        mGuideWindow = new PopupWindow(mGuideView, ViewGroup.LayoutParams.MATCH_PARENT,
                                          ViewGroup.LayoutParams.MATCH_PARENT);
        int[] location = new int[2];
        sideBarView.promotions.getLocationOnScreen(location);//获取在整个屏幕内的绝对坐标
        View view =
            (View) LayoutInflater.from(this).inflate(R.layout.layout_wallet_guide_view, null);
        int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        view.measure(w, h);
        int height = view.getMeasuredHeight();
        RelativeLayout.LayoutParams params =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                                               RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.setMargins(MARGIN_LEFT, location[1] - height, MARGIN_RIGHT, 0);
        mGuideView.addView(view, params);
        // 设置点击窗口外边窗口消失
        mGuideWindow.setOutsideTouchable(true);
        mGuideWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        mGuideWindow.setFocusable(true);
        mGuideWindow.setClippingEnabled(false);
        mGuideWindow.showAtLocation(mGuideView, Gravity.CENTER, 0, 0);
    }
    Preferences.saveBoolean(Preferences.SHOW_DRAWER_GUIDE, true);
    mGuideView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mGuideWindow != null && mGuideWindow.isShowing()) {
                mGuideWindow.dismiss();
            }
        }
    });
}

​方式二:ViewStub

 <ViewStub
        android:id="@+id/id_guide_vs"
        android:inflatedId="@+id/inflatedStart"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout="@layout/layout_wallet_guide"
        />
 
mViewStub = (ViewStub) findViewById(R.id.id_guide_vs);
 
private void showGuide(){
        RelativeLayout rl = (RelativeLayout) mViewStub.inflate();
        int[] location = new int[2];
        sideBarView.promotions.getLocationOnScreen(location);//获取在整个屏幕内的绝对坐标
        View view =
            (View) LayoutInflater.from(this).inflate(R.layout.layout_wallet_guide_view, null);
        int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        view.measure(w, h);
        int height = view.getMeasuredHeight();
        RelativeLayout.LayoutParams params =
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                                               RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.setMargins(MARGIN_LEFT, location[1] - height, MARGIN_RIGHT, 0);
        rl.addView(view, params);
        Preferences.saveBoolean(Preferences.SHOW_DRAWER_GUIDE, true);
        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mViewStub.setVisibility(View.GONE);
            }
        });
    }

    以上就是短视频软件开发,动态计算在指定位置添加view,实现引导页效果实现的相关代码, 更多内容欢迎关注之后的文章

 

posted @ 2021-12-02 14:08  云豹科技-苏凌霄  阅读(85)  评论(0编辑  收藏  举报