1

RecyclerView list item created using CardView is not equal on different android versions. The same with the tabs. How can I make them look same on each device?

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>

on Android 6.0

enter image description here

on Android 4.4

enter image description here

on Android 4.4 (with out cardCornerRadius attribute)

enter image description here

Marat
  • 6,142
  • 6
  • 39
  • 67

1 Answers1

2

Try calling: setPreventCornerOverlap(false/true); on your CardView.

refer here :https://medium.com/@etiennelawlor/layout-tips-for-pre-and-post-lollipop-bcb2e4cdd6b2#.89mmrla2j

Note: you can also set this attribute in xml cardview:cardUseCompatPadding="true/false"

SaravInfern
  • 3,338
  • 1
  • 20
  • 44
  • I would also appreciate if you could help me with tabs design. Why there is a separating line in older versions while it is not the case on android 6.0? – Marat Jul 22 '16 at 17:34