card_view:cardElevation仅出现在api< 21

时间:2014-12-23 08:38:44

标签: android android-layout android-5.0-lollipop android-cardview

我目前正在尝试使用CardView的cardElevation属性。虽然高度和阴影在KitKat上完美运行,但它并没有出现在我的Lollipop设备上。这是我的XML:

<?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:card_view="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="72dp">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        card_view:cardElevation="4dp"
        card_view:cardCornerRadius="2dp"
        card_view:cardUseCompatPadding="true">

        <!--Stuff on card view-->


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

2 个答案:

答案 0 :(得分:3)

您可以将cardUseCompatPadding设置为true以强制执行CardView为L中的阴影添加内部填充。

答案 1 :(得分:2)

这种情况正在发生,因为Lollipop上的阴影会被CardView的边界剪切掉。您需要向RelativeLayout添加一些填充或向android:clipChildren="false"添加RelativeLayout

相关问题