Создание LinearLayout с прокруткой ListView - PullRequest
0 голосов
/ 25 мая 2018

У меня есть линейный макет, который выглядит примерно так:

<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>

с несколькими ImageView с, TextInputLayout с и TextInputEditText с между ними.Я хочу сделать этот макет прокручиваемым.Я пытался сделать его прокручиваемым с ScrollView и NestedScrollView, но оба они испортили ListView.

Я также динамически изменяю содержимое ListView, и у меня есть несколько TextInputEditTextвнутри TextInputLayout внутри ListView.Изменение размера ListView не очень помогает, и я не могу нажать на TextInputEditText внутри ListView.Кажется, что ScrollView захватывает сенсорный ввод.

Существуют ли какие-либо обходные пути, которые позволят мне иметь ListView внутри ScrollView или сделать линейную раскрутку прокручиваемой, а TextInputEditText внутриListView можно использовать?

1 Ответ

0 голосов
/ 25 мая 2018

Используйте 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);
...