Android + CardView 为非 L 版本增加边距?

标签 android android-5.0-lollipop

相同的布局,但 L 和所有其他版本之间的渲染不同。

4.1.2

enter image description here

5.0

enter image description here

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="0dp"
    android:background="#FFFFFFFF"
    android:elevation="40dp"
    android:padding="0dp"
    android:translationZ="0dp"
    app:cardBackgroundColor="#FFFFFFFF"
    app:cardCornerRadius="2dp"
    app:cardElevation="40dp"
    app:cardPreventCornerOverlap="true"
    app:cardUseCompatPadding="true"
    app:contentPadding="10dp" >

    <TextView
        android:layout_width="wrap_content"
        android:gravity="center_horizontal"
        android:layout_gravity="center_vertical"
        android:layout_height="wrap_content"
        android:background="#FFFFFFFF"
        android:text="TEXTVIEW" />
</android.support.v7.widget.CardView>

最佳答案

这是按预期工作的。 L 之前的阴影是“模拟的”。来自documentation “CardView 使用 L 上的高程属性作为阴影,并回退到旧平台上的自定义阴影实现。”您应该阅读其他兼容性问题。特别是,确保将 useCompatPadding 设置为 true 以保持一致性。

关于Android + CardView 为非 L 版本增加边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26457010/

相关文章:

android - 构建安卓内核失败

java - Android FTP 库

java - 使用手机登录 Firebase 返回空指针

android - 如何设置完全脱机的Cordova构建?

java - Android Studio with libGdx(Java) - 音乐可以在 Android 模拟器上运行,但不能在桌面上运行

Android XMPP 避免资源冲突

适用于手机和电视的 Android 通用应用程序 (Lollipop)

android - Android Lollipop 上的海拔不工作

android - ActionBar/Toolbar 未显示在 Lollipop 版本的应用程序上

android - 从沉浸式模式返回时操作栏显示不正确