[英]Making LinearLayout with ListView scrollable
I have a linear layout that looks something like this: 我有一个看起来像这样的线性布局:
<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>
With a few ImageView
s, TextInputLayout
s and TextInputEditText
s in between. 中间有几个
ImageView
, TextInputLayout
和TextInputEditText
。 I want to make this layout scrollable. 我想使此布局可滚动。 I tried to make it scrollable with
ScrollView
and NestedScrollView
, but both of them messed the ListView
up. 我试图使它与
ScrollView
和NestedScrollView
一起ScrollView
,但是它们都弄乱了ListView
。
I am also changing the ListView
contents dynamically and I have a few TextInputEditText
s inside TextInputLayout
s inside the ListView
. 我也改变了
ListView
动态内容,我有几个TextInputEditText
在s TextInputLayout
的在s ListView
。 Resizing the ListView
doesn't help much, and I cannot click on the TextInputEditText
inside the ListView
. 调整
ListView
大小没有太大帮助,并且我无法单击ListView
内的TextInputEditText
。 It seems that the ScrollView
captures the touch input. 似乎
ScrollView
捕获了触摸输入。
Are there any workarounds that will let me have a ListView
inside a ScrollView
or make the linear layout scrollable while making the TextInputEditText
inside the ListView
usable? 有什么变通办法可以让我在
ScrollView
内使用ListView
或使线性布局可滚动,同时使ListView
内的TextInputEditText
可用?
Use RecyclerView
instead of ListView
and add NestedScrollView
on top: 使用
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>
and finally in your code add: 最后在您的代码中添加:
RecyclerView.setNestedScrollingEnabled(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.