CardView高程不适用于Android 5.1.1 [英] CardView elevation not working on Android 5.1.1

查看:70
本文介绍了CardView高程不适用于Android 5.1.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在RecyclerView中使用CardView。
阅读了很多书之后,我最终只在Android 5.1.1上遵循了 NOT WORKING代码。

I am using CardView inside a RecyclerView. After reading a lot I ended up with following 'NOT WORKING' code only on Android 5.1.1. On Android Version prior to this one its working nice.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#11ffffff"
    android:orientation="vertical"
    android:paddingBottom="10dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#11ffffff">
        <android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@color/primary_bg_light"
            card_view:cardCornerRadius="2dp">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/primary_bg_light">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:paddingBottom="15dp"
                        android:paddingLeft="15dp"
                        android:textColor="@color/background_floating_material_light"
                        android:textSize="24sp"
                        android:textStyle="bold" />

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

我也尝试过使用代码设置海拔高度,但结果相同。

I did try setting elevation using code also but same result.

推荐答案

要使其在api 21上方或下方均兼容,您需要在支持CardView中指定app:cardUseCompatPadding = true。

To make it both compatible above or below api 21, you need to specify app:cardUseCompatPadding="true" in your support CardView.

<android.support.v7.widget.CardView
        app:cardElevation="4dp"
        app:cardUseCompatPadding="true"
        app:cardMaxElevation="6dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
</android.support.v7.widget.CardView>

这篇关于CardView高程不适用于Android 5.1.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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