CardView和Tabs设计在早期版本的android

时间:2016-07-22 17:02:51

标签: android android-recyclerview android-cardview

使用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上的

enter image description here

Android 4.4上的

enter image description here

Android 4.4上的

(带有cardCornerRadius属性)

enter image description here

1 个答案:

答案 0 :(得分:2)

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

请参阅此处:https://medium.com/@etiennelawlor/layout-tips-for-pre-and-post-lollipop-bcb2e4cdd6b2#.89mmrla2j

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

相关问题