问题
我在包含 NestedScrollView 和 ConstraintLayout 的 Android XML 布局中遇到滚动问题。尽管将 NestedScrollView 配置为允许在内容超出屏幕大小时滚动,但滚动行为似乎并未在 WebView 内按预期工作。
这是我的 XML 布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollContainer"
android:background="@color/white"
android:fitsSystemWindows="true"
android:padding="5dp"
>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:fillViewport="true"
android:fitsSystemWindows="true"
android:scrollbars="none">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/topContainer"
android:background="@color/white"
android:clickable="true"
android:contentDescription="@string/content_description_phone_input_container"
android:focusable="true">
<WebView
android:id="@+id/webView"
android:layout_width="@dimen/_270sdp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/standard"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toStartOf="@id/guideEnd"
app:layout_constraintHorizontal_bias="0.619"
app:layout_constraintStart_toEndOf="@id/guideStart"
app:layout_constraintTop_toBottomOf="@+id/step5img"
tools:ignore="WebViewLayout">
</WebView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
尽管设置 fillViewport="true" 和 android:fitsSystemWindows="true",滚动行为似乎并未按预期工作。特别是ConstraintLayout里面的WebView是不能滚动的。
我已经确认ConstraintLayout内的内容超出了屏幕尺寸,并且我可以滚动浏览整个内容。但是,我在滚动浏览 WebView 中的内容时遇到困难。
任何有关如何解决此问题的见解或建议将不胜感激!
你可以尝试删除NestedScrollView吗?我自己的项目中不需要这样的东西。
只需添加
settings.javaScriptEnabled = true