繁体   English   中英

Cardview - 带透明背景的圆角

[英]Cardview - rounded corners with transparent background

我正在尝试一些我认为不需要几个小时的东西。 我想要一个带有透明背景和稍微圆角的卡片视图。 最后它应该是这样的(顶部的粉红色项目是其他视图):

在此处输入图片说明

这是我有多远:

在此处输入图片说明

其实我以为我已经完成了,我只需要圆角,并从卡片视图中删除笔划。 好吧,似乎这两件事是不可能的。 当我设置app:cardCornerRadius="8dp"这是我得到的输出:

在此处输入图片说明

去除中风根本不起作用。 最后,我在 drawable 中创建了一个矩形形状(我将笔划设置为 0dp),将其分配给 cardview 并且笔划消失了,但是我在圆角后面有一个白色背景,我无法将其删除。

这是我的 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?

删除 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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM