Android ConstraintLayout:创建一个按钮,用于填充RecyclerView后的空间
我有一个水平循环视图在一个约束窗口中。我想在RecyclerView的末尾放置一个按钮。当回收器为空时,按钮应扩展到所有可用空间。当物品被添加到回收器中时,按钮应压到最小值 ConstraintLayout 1.1.0中增加了一些新功能,如Android ConstraintLayout:创建一个按钮,用于填充RecyclerView后的空间,android,android-layout,android-recyclerview,android-constraintlayout,recyclerview-layout,Android,Android Layout,Android Recyclerview,Android Constraintlayout,Recyclerview Layout,我有一个水平循环视图在一个约束窗口中。我想在RecyclerView的末尾放置一个按钮。当回收器为空时,按钮应扩展到所有可用空间。当物品被添加到回收器中时,按钮应压到最小值 ConstraintLayout 1.1.0中增加了一些新功能,如layout\u constraintWidth\u min,但我无法让它正常工作。它应该按照我的意愿工作吗 以下是相关属性,不包括高度: <android.support.v7.widget.RecyclerView android:id="@
layout\u constraintWidth\u min
,但我无法让它正常工作。它应该按照我的意愿工作吗
以下是相关属性,不包括高度:
<android.support.v7.widget.RecyclerView
android:id="@+id/horizontal_recycler"
android:layout_width="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/add">
</android.support.v7.widget.RecyclerView>
及
所以这里是我的解决方案
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_marginEnd="80dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="ADD"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/recyclerView"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
请注意,为了防止recyclerView挤压按钮,回收器上的边距端应与按钮相等,并加上您认为合适的任何填充物和边距。如果recyclerView的视图多于父视图的高度,您是否想查看按钮,或者,当您滚动到最后时,是否希望它变得可见。具有预期行为的草图会很棒。我希望它始终可见(当有更多视图时,将其限制在最小值),但是在卷轴的末尾显示它的解决方案可能很有趣,如果你想在卷轴的末尾添加一个页脚,你可以在recyclerView中添加页脚。如果没有,我认为问题是你有recyclerView的包装内容,所以我认为你应该在recyclerView中添加一个最大宽度,并使按钮在剩余空间中展开。我将在2分钟内提交一个布局作为un答案。请同时提及带有回收器页脚/页眉的解决方案。您可以看到这个示例,您应该使用Ctrl+K或Cmd+K来正确设置源代码块的格式。
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_marginEnd="80dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="ADD"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/recyclerView"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>