【发布时间】:2018-07-26 00:14:15
【问题描述】:
我有一个 RecyclerView 我正在尝试用 CardView 对象填充。每个的根视图是 ConstraintLayout。
我希望我的 Recyclerview 中的卡片每张占据 25% 的垂直屏幕空间并堆叠起来。我使用了各种准则来设置这些约束。
我注意到,虽然我可以查看 CardView,但卡片之间有足够的空间。当我希望 CardView 相互堆叠时,RecyclerView 似乎正在填充 match_parent 高度的视图:
回收站视图:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_ingredients"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</android.support.v7.widget.RecyclerView>
个人卡片视图:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">
<android.support.constraint.Guideline
android:id="@+id/guideline_zero"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent=".025" />
<android.support.constraint.Guideline
android:id="@+id/guideline_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.975" />
<android.support.constraint.Guideline
android:id="@+id/guideline_two"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.025" />
<android.support.constraint.Guideline
android:id="@+id/guideline_four"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.25" />
<android.support.v7.widget.CardView
android:id="@+id/recipe_cardview"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toStartOf="@+id/guideline_one"
app:layout_constraintStart_toStartOf="@+id/guideline_zero"
app:layout_constraintTop_toTopOf="@+id/guideline_two"
app:layout_constraintBottom_toTopOf="@+id/guideline_four">
<TextView
android:id="@+id/id_of_recipe_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
【问题讨论】:
标签: java android xml android-recyclerview android-constraintlayout