Cardview 阴影没有出现在棒棒糖设备中? [英] Cardview shadow not appearing in lollipop devices?

查看:26
本文介绍了Cardview 阴影没有出现在棒棒糖设备中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 android 应用中使用 cardview.但是阴影没有显示.这是xml布局

Am using the cardview in my android app. However the shadow is not showing. Here is the xml layout

默认选项菜单阴影也没有显示.

The default optionsmenu shadow also not showing.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
    android:background="#ECEDF0"
    android:orientation="vertical" >

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:clipChildren="false"
        card_view:cardBackgroundColor="@color/white"
        card_view:cardCornerRadius="4dp"
        card_view:cardElevation="14dp"
        card_view:cardUseCompatPadding="true" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="20dp"
            android:text="Google Play" />
    </android.support.v7.widget.CardView>

</LinearLayout>

推荐答案

再次翻阅文档后,终于找到了解决方案.

After going through the docs again, I finally found the solution.

只需将 card_view:cardUseCompatPadding="true" 添加到您的 CardView 中,Lollipop 设备上就会出现阴影.

Just add card_view:cardUseCompatPadding="true" to your CardView and shadows will appear on Lollipop devices.

发生的情况是,CardView 中的内容区域在预棒棒糖和棒棒糖设备上采用不同的大小.所以在棒棒糖设备中,阴影实际上被卡片覆盖,所以它不可见.通过添加此属性,所有设备的内容区域都保持不变,并且阴影变得可见.

What happens is, the content area in a CardView take different sizes on pre-lollipop and lollipop devices. So in lollipop devices the shadow is actually covered by the card so its not visible. By adding this attribute the content area remains the same across all devices and the shadow becomes visible.

我的 xml 代码如下:

My xml code is like :

<android.support.v7.widget.CardView
    android:id="@+id/media_card_view"
    android:layout_width="match_parent"
    android:layout_height="130dp"
    card_view:cardBackgroundColor="@android:color/white"
    card_view:cardElevation="2sp"
    card_view:cardUseCompatPadding="true"
    >
...
</android.support.v7.widget.CardView>

这篇关于Cardview 阴影没有出现在棒棒糖设备中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆