【问题标题】:Android CardView Elevation not working anymoreAndroid CardView Elevation 不再工作
【发布时间】:2020-09-06 00:36:21
【问题描述】:

我面临一个奇怪的问题,即 android CardView cardElevation 在任何 API 级别都不再工作,甚至我的旧项目也没有显示过去可以正常工作的 cardElevation,即使我尝试了完全空的项目但得到了同样的问题。

已经讨论了很多与此相关的问题,我在互联网和本网站上尝试了所有可能的解决方案,但我无法解决问题。我正在使用最新版本的 Android Studio 3.3,Android Studio 中是否有任何错误或我遗漏了什么?

<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>

【问题讨论】:

  • 尝试给它 2 dp 的边距
  • 我已经试过了
  • 你能给我看看你的移动预览和 build.gradle 文件吗?

标签: android cardview elevation


【解决方案1】:

只需从清单文件 android:hardwareAccelerated="false" 中删除这一行,然后再次构建项目,它应该可以工作。

【讨论】:

    【解决方案2】:

    使用这个依赖你可以从 Post API 21 中实现提升

    implementation 'com.google.android.material:material:1.0.0'
    
    <com.google.android.material.card.MaterialCardView
            android:elevation="4dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    </com.google.android.material.card.MaterialCardView>
    

    【讨论】:

    • 好的,我会尝试并告诉您,但想解释一下为什么之前的工作不像以前那样工作..
    猜你喜欢
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 2021-05-04
    相关资源
    最近更新 更多