android开发分享在Android 5.0上的AppCompat CardView上设置XML的高程

据我所知,在预览阶段的早期,似乎没有办法只在CardView上设置XML的高程,而没有在Java中进行破解。 现在官方发布了,有没有办法在XML中这样做,而不用编写Java代码来设置高程?

我已经试过card_view:cardElevation没有效果。 我曾经想过,当我使用5.0的模拟器一切都很好。 但是现在我正在使用我的实际设备上的正式版本,所有的CardView消失了

前棒棒糖,它的效果很好。

这是我的完整的XML

 <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="https://schemas.android.com/apk/res/android" xmlns:card_view="https://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"> 

    它看起来像一个边距/填充问题,尝试将cardUseCompatPadding属性设置为true。 例如:

     <android.support.v7.widget.CardView xmlns:android="https://schemas.android.com/apk/res/android" xmlns:card_view="https://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"> 

    来自Android文档的解释:

    CardView添加额外的填充以在L之前的平台上绘制阴影。

    这可能会导致卡在L和L之间具有不同的大小。如果您需要将CardView与其他视图alignment,则可能需要使用特定于版本的维度资源来说明更改。 或者,您可以将cardUseCompatPadding标志设置为true,CardView将在平台L和之后添加相同的填充值。

    由于将cardUseCompatPadding标志设置为true会在UI中添加不必要的空白,默认值为false。

    您必须使用cardElevation属性

     <android.support.v7.widget.CardView xmlns:card_view="https://schemas.android.com/apk/res-auto" card_view:cardElevation="4dp" /> 

    如果你有这条线

    机器人:硬件加速=“假”

    在清单应用程序标记中,不显示阴影。 尝试

    删除这一行

    要么

    使用android:hardwareAccelerated =“true”

    。 这对我有用! 我希望它也能为你工作:)

      以上就是android开发分享在Android 5.0上的AppCompat CardView上设置XML的高程相关内容,想了解更多android开发(异常处理)及android游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/addevelopment/515742.html

      (0)
      上一篇 2020年12月1日
      下一篇 2020年12月1日

      精彩推荐