【问题标题】:How can I put a Webview below other views and scroll all views together如何将 Webview 放在其他视图下方并将所有视图一起滚动
【发布时间】:2017-06-02 10:49:21
【问题描述】:

我正在开发一个 android 应用程序,我在其他视图下方有一个 webview。

整个内容不适合屏幕,所以我想启用一些滚动功能。

我的布局文件如下所示:

<android.support.constraint.ConstraintLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="8dp">

    <TextView .../>
    <TextView .../>
    <TextView .../>
    <TextView .../>

    <WebView
        android:id="@+id/about_detail"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        android:textSize="14sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/contactInformation"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />

</android.support.constraint.ConstraintLayout>

我应该在我的 ConstraintLayout 周围使用 Scrollview,或者我该怎么做?

【问题讨论】:

  • 应该可以通过添加一个 ScrollView 作为您的 ConstraintLayout 的第一个子项,并添加更多元素作为 ScrollView 的子项。
  • 我把一个滚动视图作为我的约束布局中的第一个子视图,但现在只有 webview 是可滚动的,而不是之前的视图。

标签: android scroll android-webview android-scrollview android-constraintlayout


【解决方案1】:

你可以试试下面的代码:

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView .../>
        <TextView .../>
        <TextView .../>
        <TextView .../>

        <WebView
            android:id="@+id/about_detail"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="24dp"
            android:textSize="14sp" />
    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-22
    • 2018-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-18
    • 1970-01-01
    相关资源
    最近更新 更多