CardView 上的透明背景 - Android [英] Transparent background on CardView - Android
问题描述
我想在 CardView 上做透明背景.我知道背景颜色,但我的布局上有图像.
I want to do transparent background on CardView. I know backgroundColor but i have image on my Layout.
你知道怎么做吗?或者可以用作cardview但我会设置透明背景的东西?
Do you know how do it? Or something which work as cardview but i will set a transparent background?
问候
推荐答案
设置你的 CardView 使用 cardBackgroundColor
属性来移除颜色和 cardElevation
属性来移除阴影.例如:
Setup your CardView to use the cardBackgroundColor
attribute to remove color and cardElevation
attribute to remove the drop shadow. For example:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myCardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardBackgroundColor="@android:color/transparent"
card_view:cardElevation="0dp">
有关受支持属性的完整列表,请参见此处:https://developer.android.com/reference/android/support/v7/widget/CardView.html
For a full list of supported attributes see here: https://developer.android.com/reference/android/support/v7/widget/CardView.html
如果您使用的是较旧的 API,则需要在 CardView
上调用这两个函数:
If you are using an older API, you will need to call these two functions on your CardView
instead:
myCardView.setCardBackgroundColor(Color.TRANSPARENT);
myCardView.setCardElevation(0);
这篇关于CardView 上的透明背景 - Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!