我有一个看起来像这样的线性布局:
<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
内容,并且在 ListView
内的 TextInputLayout
内有一些 TextInputEditText
。调整 ListView
的大小没有多大帮助,而且我无法单击 ListView
内的 TextInputEditText
。看来 ScrollView
捕获了触摸输入。
是否有任何解决方法可以让我在 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);
关于java - 使 LinearLayout 与 ListView 可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50524337/