具有包装内容行为的androidx Recycler View匹配约束(0dp) [英] androidx Recycler View match constraint (0dp) with wrap content behaviour
本文介绍了具有包装内容行为的androidx Recycler View匹配约束(0dp)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里有一个简单的回收站视图,我想要的是:
I have simple recycler view here, what I want is:
列表短时:将按钮粘贴在回收者"视图下方
列表较长时:将按钮保留在屏幕底部,但回收站视图正确包装并且可以滚动到底部
<?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">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_user_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="20dp"
app:layout_constraintBottom_toTopOf="@id/btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintVertical_bias="0.0"
tools:itemCount="50"/>
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:text="example"
android:background="#00ffff"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="@id/rv_user_address"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
何时 wrap_content
:
<androidx.recyclerview.widget.RecyclerView
android:layout_height="wrap_content"
...
短列表可以将按钮正确地粘在下方,但是长列表时按钮会不在屏幕上
short-list can stick button below properly but button is off screen when list is long
何时受约束: 0dp
:
<androidx.recyclerview.widget.RecyclerView
android:layout_height="0dp"
...
长列表是正确的行为,但短列表不是列表下方的固定按钮
long list is correct behavior but short-list not stick button below list
我不知道了.感谢您的帮助.
I am out of idea. Thanks for helping.
推荐答案
只需添加以下行:
app:layout_constrainedHeight="true"
以以下方式进入您的Recyclerview:
to your Recyclerview as:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_user_address"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="20dp"
app:layout_constrainedHeight="true" <-- Add this line
app:layout_constraintBottom_toTopOf="@id/btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintVertical_bias="0.0"
tools:itemCount="50"/>
这篇关于具有包装内容行为的androidx Recycler View匹配约束(0dp)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文