CardView elevation not working on Android 5.1.1

前端 未结 5 1569
面向向阳花
面向向阳花 2021-01-01 07:18

I am using CardView inside a RecyclerView. After reading a lot I ended up with following \'NOT WORKING\' code only on Android 5.1.1. On Android Version prior to this one its

相关标签:
5条回答
  • 2021-01-01 07:39

    Just simply add this code to your Card View in xml file!

        card_view:cardUseCompatPadding="true"
    

    You have to import card_view with Alt+Enter ! And code below will be import in top !.

      xmlns:card_view="http://schemas.android.com/apk/res-auto"
    

    You'll see elevation is working on android 5 or 5+ .

    0 讨论(0)
  • 2021-01-01 07:40

    remove this line from <application ...> </application> in AndroidManifest.xml file

    android:hardwareAccelerated="false"
    

    change to

    android:hardwareAccelerated="true"
    

    for more details Hardware acceleration

    0 讨论(0)
  • 2021-01-01 07:45

    Remove below line if you used in AndroidManifest.xml

    android:hardwareAccelerated="false"
    
    0 讨论(0)
  • 2021-01-01 07:49

    set in card view

    <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="match_parent"
    android:layout_margin="6dp"
    card_view:cardUseCompatPadding="true"
    card_view:cardElevation="4dp"
    card_view:cardCornerRadius="3dp">
    
    0 讨论(0)
  • 2021-01-01 08:02

    To make it both compatible above or below api 21, you need to specify app:cardUseCompatPadding="true" in your support CardView.

    <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>
    
    0 讨论(0)
提交回复
热议问题