android 早期版本的 CardView 和 Tabs 设计不同

CardView and Tabs designs are different on earlier versions of android

使用 CardView 创建的 RecyclerView 列表项在不同 android 版本上不相同。与选项卡相同。如何让它们在每台设备上看起来都一样?

gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.3'

    defaultConfig {
        applicationId "com.example.marat.days"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.android.support:percent:23.4.0'
    compile 'com.android.support:cardview-v7:23.4.0'
    compile 'com.android.support:recyclerview-v7:23.4.0'
}

list_item.xml:

<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="wrap_content"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?android:attr/selectableItemBackground"
    card_view:cardElevation="5dp"
    card_view:cardCornerRadius="20dp">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:baselineAligned="false">

            // other lines of code
            // if you need it let me know

        </LinearLayout>

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

上 Android 6.0

在 Android 4.4

在 Android 4.4(没有 cardCornerRadius 属性)

尝试在您的 CardView 上调用:setPreventCornerOverlap(false/true);

参考这里:https://medium.com/@etiennelawlor/layout-tips-for-pre-and-post-lollipop-bcb2e4cdd6b2#.89mmrla2j

注意:您也可以在xml中设置该属性 cardview:cardUseCompatPadding="true/false"