问题描述
我用我的Android应用程序的cardview。然而,阴影未显示。这里是XML布局
Am using the cardview in my android app. However the shadow is not showing. Here is the xml layout
默认optionsmenu影子也没有显示。
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 =真正的
您 CardView
和阴影将出现在棒棒糖设备
Just add card_view:cardUseCompatPadding="true"
to your CardView
and shadows will appear on Lollipop devices.
会发生什么事,在内容领域 CardView
采取pre-棒棒糖和棒棒糖设备不同的大小。因此,在棒棒糖设备的阴影实际上是涵盖了卡,它不可见。通过加入该属性的内容面积保持所有设备相同,阴影变得可见。
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 code是这样的:
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影子都没出现在棒棒糖的设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!