7

我需要BottomSheet停在两个位置。我有以下代码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,然后我可以向下滚动它。我不能直接向下滚动工作表。

任何帮助将不胜感激。

4

3 回答 3

31

我不知道这是否可以解决您的问题,但我通过将inBottomSheet替换为a解决了 a 中的很多滚动问题。ScrollViewBottomSheetNestedScrollView

于 2016-08-02T14:38:03.280 回答
5

希望在这里您能找到解决方案

https://www.androidhive.info/2017/12/android-working-with-bottom-sheet/

ScrollView并改变NestedScrollView

ps 实际上那里的代码太多了

于 2018-09-23T08:30:31.070 回答
0

这对我有用,

  • 将嵌套滚动视图设置为父级

  • 使回收站视图高度 wrap_content

于 2019-10-31T10:52:49.313 回答