繁体   English   中英

如何使GridLayout背景透明?

[英]How to Make GridLayout Background Transparent?

我在回收器视图中实现GridLayout,并从drawable文件夹中加载了Images。

图片链接在这里

如您所见,背景为白色,我想使其透明,此布局的XML代码为

<?xml version="1.0" encoding="utf-8"?>


<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000"
    android:id="@+id/card"
    card_view:cardCornerRadius="3dp"
    card_view:cardElevation="2dp"
    card_view:cardUseCompatPadding="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="4dp"
        android:scaleType="centerCrop" />
    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:text="Abcd"
        android:textSize="18dp"
        android:textStyle="bold"
        android:textAllCaps="true"
        android:textColor="#ffffff"
        android:layout_marginTop="140dp"/>
</RelativeLayout>


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

我尝试了很多事情,例如:

  • 使Recycler View的Alpha为0
  • 卡片视图的Alpha为0
  • 将卡片背景色设置为透明并将最大高程设置为0,以减少阴影

不过,我仍然无法获得透明的背景。 谁能建议一种新方法?

另外,使用的图像是具有透明背景的矢量图像。

更新

现在可以使用了,感谢@Adley
我只需要删除我正在使用的卡布局并将其转换为正常的相对布局

编辑:

尝试将card_view:cardBackgroundColor="@android:color/transparent"到根视图(CardView)。

暂无
暂无

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

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