【发布时间】:2021-02-20 08:42:46
【问题描述】:
我正在尝试为我的cardView 实现一个cardCornerRadius,但它不适用于我。
这是我的 XML:
编辑:我没有提到我将 cardView 添加到 recyclerView 列表中,所以我只是调整了 recylcerView 的宽度和高度,现在它可以工作了,但是另一个问题是当我添加 ImageView 时 cardCornerRadius 无法解决 ImageView。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/journalListImageView"
android:layout_width="400dp"
android:layout_height="250dp"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:scaleType="fitXY"
android:src="@drawable/quotefancy_work_hard" />
<TextView
android:id="@+id/journalTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:padding="5dp"
android:text="Title"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/journalThoughtsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:padding="5dp"
android:text="Toughts..."
android:textSize="18sp"
android:textStyle="normal" />
<TextView
android:id="@+id/journalTimestampTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:padding="5dp"
android:text="Date created"
android:textStyle="italic" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
【问题讨论】:
-
可以加截图吗?
-
您的代码是正确的,它对我来说可以正常工作。尝试重新启动 android studio
-
为问题添加截图
-
我试过你的代码,没有发现问题。它是由包导入错误引起的还是我可以问你得到的错误信息是什么?
标签: android android-layout android-cardview