java - BottomSheet 的滚动问题 - Android

标签 java android bottom-sheet

我需要 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 然后我可以向下滚动它。我无法直接向下滚动工作表。

我们将不胜感激。

最佳答案

我不知道这是否能解决您的问题,但我通过替换 BottomSheet 中的BottomSheet 带有 NestedScrollView

关于java - BottomSheet 的滚动问题 - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37655712/

相关文章:

Android alpha 动画在动画期间不重绘

android - 当 Bottom Sheet android中的recyclerview时防止用户在 Bottom Sheet 中拖动

Android BottomSheetBehavior 回调方法 onSlide() 给出了令人困惑的 slideOffset 值

java - Gradle 获取所有依赖项的列表

android - 如何使用 Android Studio 为同一项目中的不同谷歌服务集成两个或多个 google-services.json 文件

java - 如何2 : Add a JPanel to a Document then export to PDF

android - 在 Android 布局中使用 <Space>

ios - 如何计算UIViewController内部内容的高度?

java - mAdapter.notifyDataSetChanged() 在某些情况下不起作用

java - JDBC自动查询转的很慢