短視訊軟體開發,動態計算在指定位置新增view,實現引導頁效果

zhibo系統開發發表於2021-12-02

短視訊軟體開發,動態計算在指定位置新增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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章