簡體   English   中英

BottomSheet 的滾動問題 - Android

[英]Scrolling issue with BottomSheet - Android

我需要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 ,然后我可以向下滾動它。 我不能直接向下滾動工作表。

任何幫助將不勝感激。

我不知道這是否能解決您的問題,但我通過將BottomSheetScrollView替換為NestedScrollViewBottomSheet中的NestedScrollView滾動問題。

希望在這里你能找到解決方案

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

並使用NestedScrollView更改ScrollView

ps 其實那里代碼太多了

這對我有用,

  • 將嵌套滾動視圖設置為父級

  • 使回收者視圖高度為 wrap_content

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM