如何解决持久性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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。