android - 使用 ConstraintLayout 在 RecyclerView 中 Listview 不可滚动
问题描述
我有一个RecyclerView
里面包含ListView
。我必须使用,因为我ConstraintLayout
需要为. 但是当屏幕上的内容太多时,列表视图似乎无法滚动。TextView
ListView
RecyclerView
recyclerview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textColor="#0E1C2B"
android:textSize="17sp"
app:layout_constraintBottom_toTopOf="@+id/recyclerview_list"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.333" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Date: "
android:textColor="#0E1C2B"
android:textSize="17sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.207"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="@+id/recyclerview_list"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.43"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4"
app:layout_constraintVertical_bias="0.012" />
</androidx.constraintlayout.widget.ConstraintLayout>
解决方案
*我自己的解决方案*
必须在 ListView 元素周围添加 `LinearLayout`。
那些带有星星的线条与原来的线条不同。
.
最终recyclerview_layout.xml:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
---------other code are the same------------
<LinearLayout
android:layout_width="300dp"
**android:layout_height="wrap_content"**
**android:orientation="vertical"**
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.47"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.011">
<ListView
android:id="@+id/recyclerview_list"
**android:layout_width="match_parent"**
**android:layout_height="wrap_content"**
tools:layout_editor_absoluteX="104dp"
tools:layout_editor_absoluteY="59dp" />
</LinearLayout>
推荐阅读
- mqtt - MQTT 客户端从 RTI DDS 发布者订阅数据
- tomcat - 在 Tomcat 中使用 Ember Js 和 java 后端
- r - data.matrix() 修改 R 中数据框的第一列
- java - “没有主题替代 DNS 名称匹配
发现”使用 RestTemplate 时出错 - java - 子树JPQL的意外结束
- ssms - 为什么 17.8.1 版的 SSMS-setup-ENU 没有运行?
- php - 在php中从字符串中搜索数字
- python - python实例化一个嵌套类
- c# - Selenium C# - 尽管网站可以浏览,但 HttpWebRequest 始终返回 404
- javascript - 在 Javascript 中扩展对象