umano so Three.slidinguppanel.SlidingUpPanelLayout 底部滑动面板高度因不同手机屏幕尺寸而异

问题描述 投票:0回答:1

我使用 umano so Three.slidinguppanel.SlidingUpPanelLayout 进行底部向上滑动布局。我已将 umano 面板布局的高度设置为 400dp,与我的手机小屏幕相匹配,并且设计正确。当应用程序安装在大屏幕手机上时,面板高度与设计相比非常小。

如何使面板始终保持在图像下方,并且在滚动时面板应向上滑动

    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/sliding_layout"
        android:gravity="bottom"
        sothree:umanoPanelHeight="460dp"
        sothree:umanoShadowHeight="5dp"
        sothree:umanoDragView="@+id/dragView"
        sothree:umanoOverlay="true"
        sothree:umanoScrollableView="@+id/cl_dragged_view">
android android-xml slideup
1个回答
0
投票

计算屏幕总高度。

DisplayMetrics displayMetrics = new DisplayMetrics();
                activityContext.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
                    int height1 = displayMetrics.heightPixels;

然后计算滑动面板应该接触的布局的高度

 ViewTreeObserver vto = clLottiePanel.getViewTreeObserver();
            vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        clLottiePanel.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    } else {
                        clLottiePanel.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    }
                    int height = binding.clLottiePanel.getMeasuredHeight();
                    DisplayMetrics displayMetrics = new DisplayMetrics();
                    .getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
                    int height1 = displayMetrics.heightPixels;
                    Log.d("TAG", "onGlobalLayout: ");
                  slidingLayout.setPanelHeight(height1 - height);

                }
            });

现在

sidingLayout.setPanelHeight(height1 - height); 

这给出了每个屏幕的高度,以设置面板高度。

© www.soinside.com 2019 - 2024. All rights reserved.