java - 使用 ListView 使 LinearLayout 可滚动
问题描述
我有一个看起来像这样的线性布局:
<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
s,TextInputLayout
s和TextInputEditText
s。我想让这个布局可滚动。ScrollView
我试图用and使它可以滚动NestedScrollView
,但他们都搞砸ListView
了。
我也在ListView
动态更改内容,并且TextInputEditText
在. 调整大小并没有多大帮助,我无法单击. 似乎捕获了触摸输入。TextInputLayout
ListView
ListView
TextInputEditText
ListView
ScrollView
是否有任何解决方法可以让我拥有一个ListView
内部 aScrollView
或使线性布局可滚动,同时使TextInputEditText
内部ListView
可用?
解决方案
使用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);
推荐阅读
- r - 如何从此列表中提取值(来自 rgbif)并将其转换为 R 中的数据框?
- javascript - ReactJS Moment 没有正确格式化日期
- python - “\z”锚在 Python 正则表达式中不起作用
- android - Xamarin Android INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
- pyspark - 如何遍历 spark 数据框的一列并逐个访问其中的值?
- angular - 角度反应形式 - 将 formArray 传递给子组件时出错
- r - 在 R 中创建 *NEW* 多条件(函数)列
- javascript - 如何仅随机显示一次来自对象的值
- c++ - 如何在功能实现之间交换?
- python - 函数内的 Pandas 数据类型更改