【问题标题】:Transparent CardView Child Shadow Does Not Appear透明 CardView 子阴影不出现
【发布时间】:2016-01-08 15:19:08
【问题描述】:

我有一个CardView,其中cardBackgroundColor 设置为透明。和cardElevation 设置为3dp

CardView 中有一个ImageView。我想知道为什么ImageView 上没有阴影。

注意:我特意将ImageView 包裹在CardView 中以在Pre Lollipop 设备上生成阴影,但它似乎不起作用。

有什么想法吗?

【问题讨论】:

  • 如果您将 cardBackgroundColor 更改为其他颜色会发生什么?我想,透明的东西怎么会投下阴影呢?

标签: android android-layout android-cardview


【解决方案1】:
Set padding to parent view of card view to 3dp.

Like,
<RelativeLayout 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="match_parent"
   android:padding="8dp"
    android:background="@android:color/white">

 <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="8dp"
            android:id="@+id/card1">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#FFFFFF"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/imgCard"
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_margin="10dp"
                    android:src="@drawable/add_contact" />

                <TextView
                    android:id="@+id/tvColor"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="Card View" />
            </LinearLayout>
        </android.support.v7.widget.CardView>
</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-13
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-24
    • 1970-01-01
    相关资源
    最近更新 更多