CardView 上的透明背景 - Android

新手上路,请多包涵

我想在 CardView 上做透明背景。我知道背景颜色,但我的布局上有图像。

你知道怎么做吗?或者可以用作cardview但我会设置透明背景的东西?

问候

原文由 mac229 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.8k
2 个回答

设置您的 CardView 以使用 cardBackgroundColor 属性删除颜色和 cardElevation 属性删除阴影。例如:

 <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

如果您使用的是较旧的 API,则需要在 CardView 上调用这两个函数:

 myCardView.setCardBackgroundColor(Color.TRANSPARENT);
myCardView.setCardElevation(0);

原文由 Chris Stillwell 发布,翻译遵循 CC BY-SA 3.0 许可协议

使用 app:cardBackgroundColor="@android:color/transparent"

 <android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="20dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginTop="10dp"
    app:cardCornerRadius="16dp"
    app:cardElevation="16dp"
    app:cardBackgroundColor="@android:color/transparent" >

<--inside cardlayout-->

    </android.support.v7.widget.CardView>

原文由 Kapil Parmar 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题