如何解决制作空的 LinearLayout 以填充 cardview 内的空间
我需要在 CardView 中使用一个空的 LinearLayout 来以编程方式设置背景。但是空的 LinearLayout 刚刚结束。我的 CardView 没有固定高度,所以不能给 LinearLayout 添加静态高度。
我所知道的
- 以编程方式设置 CardView 背景
- 使用与 CardView 相同的 minHeight
- 为 CardView 设置固定高度而不是 wrap_content
问题 使用 (1) cardCornerRadius 等不起作用 (2) CardView 和 LinearLayout 可以在更大的屏幕中以不同的方式缩放 (3) 我希望 CardView 在更大的屏幕上放大
这是截图
这是我的 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:id="@+id/item_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="@+id/cardViewCourse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="true"
android:focusable="true"
android:minHeight="300dp"
android:padding="@dimen/normalPadding"
android:translationZ="-4dp"
app:cardCornerRadius="15dp"
app:cardPreventCornerOverlap="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_gravity="center"
android:id="@+id/shopperCardBacground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="@drawable/gradient_cc"
android:orientation="horizontal">
</LinearLayout>
</androidx.cardview.widget.CardView>
<TextView
android:layout_margin="@dimen/normalPadding"
android:id="@+id/tv_cantidad_cursos"
android:fontFamily="@font/exo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="@string/courses_count_fake"
app:layout_constraintLeft_toLeftOf="@id/cardViewCourse"
app:layout_constraintTop_toTopOf="@id/cardViewCourse" />
<TextView
android:fontFamily="@font/alegreya"
android:id="@+id/tv_participants"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="@string/courses_read_fake"
app:layout_constraintStart_toStartOf="@id/tv_cantidad_cursos"
app:layout_constraintTop_toBottomOf="@id/tv_cantidad_cursos" />
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:src="@drawable/android_developer"
app:layout_constraintBottom_toBottomOf="@+id/cardViewCourse"
app:layout_constraintEnd_toEndOf="@+id/cardViewCourse"
app:layout_constraintStart_toStartOf="@+id/cardViewCourse"
app:layout_constraintTop_toTopOf="@+id/cardViewCourse"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/textView"
style="@style/viewParent.headerText.magazine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="Understanding 3D Screens"
app:layout_constraintBottom_toBottomOf="@+id/cardViewCourse"
app:layout_constraintLeft_toLeftOf="@id/cardViewCourse"
app:layout_constraintRight_toRightOf="@id/cardViewCourse"
app:layout_constraintTop_toBottomOf="@id/image" />
</androidx.constraintlayout.widget.ConstraintLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。