ITPub博客

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

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

原创 Java 作者:zhibo系统开发 时间:2021-12-02 14:09:24 0 删除 编辑

短视频软件开发,动态计算在指定位置添加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,实现引导页效果实现的相关代码, 更多内容欢迎关注之后的文章


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/69978258/viewspace-2845377/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2020-07-02

  • 博文量
    688
  • 访问量
    260289