BottomSheet的滚动问题-Android [英] Scrolling issue with BottomSheet - Android

查看:117
本文介绍了BottomSheet的滚动问题-Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要 BottomSheet 停在两个位置.我有 BottomSheet 的以下代码.

I need the BottomSheet to stop at two positions. I have the following code for BottomSheet.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        ....
    </RelativeLayout>

    <FrameLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
           <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:minHeight="1000dp"
                    android:orientation="vertical">
                    ....
                </LinearLayout>
          </ScrollView>
     </FrameLayout>
</android.support.design.widget.CoordinatorLayout>

View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);
final BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
    @Override
    public void onStateChanged(@NonNull View bottomSheet, int newState) {
        // React to state change
        Log.e("onStateChanged", "onStateChanged:" + newState);
        if (newState == BottomSheetBehavior.STATE_EXPANDED) {
            behavior.setPeekHeight(600);
            showAgain.setVisibility(View.GONE);
            mMap.getUiSettings().setScrollGesturesEnabled(false);
        } else if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
            if (behavior.getPeekHeight() == 600) {
                behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                behavior.setPeekHeight(80);
                mMap.getUiSettings().setScrollGesturesEnabled(false);
            } else if (behavior.getPeekHeight() == 80) {
                showAgain.setVisibility(View.VISIBLE);
                mMap.getUiSettings().setScrollGesturesEnabled(true);
            }
        }
    }
    
    @Override
    public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        // React to dragging events
        Log.e("onSlide", "onSlide " + slideOffset);
    }
});
    
behavior.setPeekHeight(600);

除了一件事情外,这段代码可以正常工作.第一次,我必须向上滚动 BottomSheet ,然后向下滚动.我不能直接向下滚动页面.

This code works fine except one thing. The very first time I have to scroll up the BottomSheet and then I can down scroll it. I cannot directly down scroll the sheet.

任何帮助将不胜感激.

推荐答案

我不知道这是否可以解决您的问题,但是我在 BottomSheet 通过将 BottomSheet 中的 ScrollView 替换为 NestedScrollView .

I don't know if this will be a solution to your problem, but I fixed quite a bit of scroll issues in a BottomSheet by replacing the ScrollView in the BottomSheet with a NestedScrollView.

这篇关于BottomSheet的滚动问题-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆