Cardview-具有透明背景的圆角

时间:2020-03-10 18:43:36

标签: android layout android-recyclerview android-cardview

我正在尝试一些我认为不会花费数小时的事情。 我想使用透明背景和略圆角的Cardview。 最后,它应该看起来像这样(顶部的粉红色项目是其他视图):

enter image description here

这是我走了多远:

enter image description here

实际上,我认为我已经完成了,我只需要拐角处,然后从卡片视图中移除笔划。好吧,似乎这两件事是不可能的。当我设置app:cardCornerRadius="8dp"时,我得到的输出是:

enter image description here

删除笔划根本没有用。最后,我在drawable内部创建了一个矩形形状(将笔划设置为0dp),将其分配给cardview,笔划消失了,但是圆角后面有一个白色背景,因此我无法将其删除。 / p>

这是我的CardView布局:

<androidx.cardview.widget.CardView
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_margin="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:elevation="0dp"
app:cardCornerRadius="8dp"
app:cardPreventCornerOverlap="true"
app:cardBackgroundColor="#00123456"
> </CardView>

是否有可能达到我想要的(第一张照片)?还是应该让RecyclerView切换到ListView?

1 个答案:

答案 0 :(得分:0)

删除CardView作为父对象并放置Constraintlayout解决了问题。

<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"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/rounded_background"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
android:paddingTop="4dp"></ConstraintLayout>
相关问题