繁体   English   中英

cardview未将背景设置为透明

[英]cardview not setting background to transparent

嗨,我有一个Cardview位于视图的中心,我想使其背景透明。 但它似乎没有这样做,并且背景为白色

这是我的xml

<android.support.v7.widget.CardView
    android:id="@+id/boundaryBox"
    android:layout_width="270dp"
    android:layout_height="176dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    card_view:cardBackgroundColor="@android:color/transparent"
    card_view:cardElevation="0dp"
    card_view:cardCornerRadius="14dp" />

您是否检查了父级布局是否具有任何背景,因为如果尝试以下代码,则cardview将是透明的。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorAccent"
    android:padding="@dimen/dp_16"
    tools:context=".MainActivity">

    <android.support.v7.widget.CardView
        android:id="@+id/boundaryBox"
        android:layout_width="match_parent"
        android:layout_height="176dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:cardBackgroundColor="@android:color/transparent"
        app:cardElevation="16dp"
        app:cardCornerRadius="14dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="test"/>
    </android.support.v7.widget.CardView>
</RelativeLayout>

请尝试这个。

暂无
暂无

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

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