CardView not showing shadow elevation

前端 未结 17 1243
广开言路
广开言路 2020-12-14 16:32

I am working with cardviews but the problem is my CardView is not showing any elevation or shadow. I have already tried some of the methods suggested in stackoverflow answer

相关标签:
17条回答
  • 2020-12-14 17:00
    <android.support.v7.widget.CardView android:id="@+id/item_card"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        app:cardCornerRadius="2dp"
        app:cardUseCompatPadding="true"
        app:cardElevation="2dp"
        app:cardBackgroundColor="@color/md_white_1000"
        android:foreground="?android:attr/selectableItemBackground"
        android:clickable="true">
    
    </android.support.v7.widget.CardView>
    

    app:cardUseCompatPadding="true" is the main catch here

    0 讨论(0)
  • 2020-12-14 17:02

    use this inside cardView to show shadow:

    app:cardElevation="4dp"
    app:cardMaxElevation="4dp"
    
    0 讨论(0)
  • 2020-12-14 17:04

    Try this

        <android.support.v7.widget.CardView
                android:id="@+id/driverCurrentJobsCardView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/dim_8"
                android:background="#ffffff"
                app:cardCornerRadius="4dp"
                card_view:cardElevation="4dp"/>
    

    And make sure that you are using this dependency in gradle

    compile 'com.android.support:cardview-v7:23.2.1'
    
    0 讨论(0)
  • 2020-12-14 17:05

    Lot of good answers, but sometimes just one doesn't work for all. here's the one that worked for me after a lot of looking around,

    Add this line to your CardView

    app:cardUseCompatPadding="true"
    

    So your cardview looks like this

      <androidx.cardview.widget.CardView
          android:id="@+id/cardView"
          android:layout_width="match_parent"
          app:cardUseCompatPadding="true"/>
    

    Hope that works! Happy coding!

    0 讨论(0)
  • 2020-12-14 17:06
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardBackgroundColor="@android:color/white"
        android:foreground="?android:attr/selectableItemBackground"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_marginTop="@dimen/padding_small"
        android:layout_marginBottom="@dimen/padding_small"
        app:cardCornerRadius="4dp"
        app:cardElevation="4dp" >
    
    </android.support.v7.widget.CardView>
    
    0 讨论(0)
提交回复
热议问题