持久性BottomSheet下拉无法与Swipe一起使用以刷新布局和WebView

问题描述

我创建了一个 BottomSheet。展开底部工作表后,由于滑动以刷新布局,我无法将其拉下。当我删除滑动以刷新布局时,向下拖动或向下滑动即可。我在多个地方和类中使用相同的 UI,所以我无法删除滑动刷新,只有当我从底部工作表调用它时才能禁用。如何通过滑动下拉底部工作表以刷新布局和 WebView。我在下面创建了一个演示项目是代码

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SwipeRefreshLayout swipe = findViewById(R.id.swipe);
        swipe.setRefreshing(false);
        swipe.setEnabled(false);
        WebView mywebview = (WebView) findViewById(R.id.webView1);
        mywebview.setWebViewClient(new WebViewClient());
        mywebview.loadUrl("https://stackoverflow.com");
    }
}

布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
     xmlns:android="http://schemas.android.com/apk/res/android"      
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
     <FrameLayout
        android:id="@+id/bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:behavior_hideable="true"
        app:behavior_peekHeight="55dp"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/swipe"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

           <WebView
               android:id="@+id/webView1"
               android:layout_width="match_parent"
               android:layout_height="match_parent"/>

        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
      </FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> 

解决方法

我通过将 SwipeRefreshLayout 封装在 NestedScrollView 中解决了这个问题。

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.core.widget.NestedScrollView
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:behavior_hideable="true"
    app:behavior_peekHeight="55dp"
    app:layout_behavior="@string/bottom_sheet_behavior">


    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipe"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <WebView
            android:id="@+id/webView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>