使用 ListView 使 LinearLayout 可滚动

Making LinearLayout with ListView scrollable

我有一个线性布局,看起来像这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear_layout"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    tools:context=".activities.EnrolStudentFormActivity">

    <include
        layout="@layout/app_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:fitsSystemWindows="true" />

    <ListView
        android:id="@+id/list_view
        android:layout_width="match_pare
        android:layout_height="wrap_cont
        android:divider="@null"
        android:dividerHeight="0dp" />

</LinearLayout>

中间有几个 ImageViewTextInputLayoutTextInputEditText。我想让这个布局可以滚动。我尝试使用 ScrollViewNestedScrollView 使其可滚动,但它们都把 ListView 弄乱了。

我也在动态更改 ListView 内容,我在 ListView 中的 TextInputLayout 中有几个 TextInputEditText。调整 ListView 的大小没有多大帮助,我无法单击 ListView 内的 TextInputEditTextScrollView 似乎捕获了触摸输入。

是否有任何变通方法可以让我在 ScrollView 中使用 ListView 或使线性布局可滚动,同时使 ListView 中的 TextInputEditText 可用?

使用 RecyclerView 代替 ListView 并在顶部添加 NestedScrollView

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="
http://schemas.android.com/apk/res/android"
xmlns:http="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    tools:context=".activities.EnrolStudentFormActivity">

    <include
        layout="@layout/app_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:fitsSystemWindows="true" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@null"
        android:dividerHeight="0dp" />>

</LinearLayout>

最后在您的代码中添加:

RecyclerView.setNestedScrollingEnabled(false);