本文介绍了设置在提升XML的AppCompat CardView在Android 5.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,在preVIEW阶段早期似乎有没有办法只对 CardView S设定海拔XML没有Java中的黑客。现在正式发布出来了,有什么办法没有编写Java code将抬高XML这样做的?

我已经试过 card_view:cardElevation 没有效果。我曾在我所用的仿真器5.0一切都很好的想法。但现在,我使用的是正式版我的实际设备上我所有的 CardView 失踪以及

pre棒棒糖,它的伟大工程。

下面是我的完整的XML

 < XML版本=1.0编码=UTF-8&GT?;
< android.support.v7.widget.CardView的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:card_view =htt​​p://schemas.android.com/apk/res-auto
    机器人:方向=横向
    机器人:layout_width =match_parent
    机器人:ID =@ + ID / CV1
    card_view:cardElevation =4DP
    机器人:layout_margin =6DP
    card_view:cardCornerRadius =3DP
    机器人:layout_height =match_parent>
 

解决方案

它看起来像一个保证金/填充的问题,尝试设置 cardUseCompatPadding 属性为true。例如:

 < android.support.v7.widget.CardView
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:card_view =htt​​p://schemas.android.com/apk/res-auto
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:layout_margin =6DP
    card_view:cardUseCompatPadding =真
    card_view:cardElevation =4DP
    card_view:cardCornerRadius =3DP>
 

这是Android的文档说明:

From what I understand, early in the preview stage there seemed to be no way to set elevation in XML only on CardViews without a hack in Java. Now that the official release is out, is there any way of doing this in XML without writing Java code to set elevation?

I have tried card_view:cardElevation to no effect. I had thought when I was using the emulators for 5.0 everything was fine. But now that I'm using the official version on my actual device all of my CardViews disappeared

Pre Lollipop, it works great.

Here is my full xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:id="@+id/cv1"
    card_view:cardElevation="4dp"
    android:layout_margin="6dp"
    card_view:cardCornerRadius="3dp"
    android:layout_height="match_parent">
解决方案

It looks like a margin/padding problem, try to set the cardUseCompatPadding attribute to true. E.g.:

<android.support.v7.widget.CardView
    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:layout_margin="6dp"
    card_view:cardUseCompatPadding="true"
    card_view:cardElevation="4dp"
    card_view:cardCornerRadius="3dp">

Explanation from Android doc :

这篇关于设置在提升XML的AppCompat CardView在Android 5.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 01:58