android - Android - 无法将视图设置为卡片内的 match_parent 高度以进行回收器视图
问题描述
我有一个回收站视图,它由一个 card_view 提供,它的左边缘有一个颜色条(视图),它应该占据卡片的整个高度。
我尝试将颜色视图的高度设置为 match_parent 但如果我这样做,颜色将永远不会出现。如果我改为为高度分配一个数字,那么它可以工作,但我需要视图来调整卡片的高度。
这是将提供给回收站视图的卡片的 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="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingEnd="14dp"
>
<View
android:id="@+id/swatch"
android:layout_width="12dp"
android:layout_height="match_parent" />
<TextView
android:id="@+id/pathTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/swatch"
android:layout_marginStart="8dp"
android:layout_marginTop="14dp"
android:padding="2dp"
android:text="@string/placeholder_title"
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/pathDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/pathTitle"
android:layout_toEndOf="@id/swatch"
android:layout_marginStart="8dp"
android:layout_marginBottom="14dp"
android:padding="2dp"
android:text="@string/placeholder_title"
android:textColor="@android:color/black"
android:textSize="14sp" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
如何让“样本”视图调整到卡片的高度?
解决方案
希望它能解决你的问题
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<View
android:id="@+id/swatch"
android:layout_width="12dp"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/pathTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="14dp"
android:padding="2dp"
android:text="@string/placeholder_title"
android:textColor="@android:color/black"
android:textSize="14sp" />
<TextView
android:id="@+id/pathDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="14dp"
android:padding="2dp"
android:text="@string/placeholder_title"
android:textColor="@android:color/black"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
推荐阅读
- amazon-ec2 - 使用 terraform 将静态 IP 地址分配给新的 aws 实例
- c# - 什么是 launchProfile.json 中的“dotnet run”默认配置文件设置?
- c++ - 如何通过带有多 for 循环的 openmp 加速我的代码
- java - 如何将带逗号的字符串转换为整数和双精度
- android - 应用在 Chrome 中运行良好,但在 Android 中运行不佳
- visual-studio-code - vsCode 终端中奇怪的字体布局?
- c++ - Extern "C" 和 C++ 结构和 typedef
- python - Python tKinter 挂起
- php - PHP:获取多选框值作为逗号分隔值
- php - 结果查询到单个字符串数组