CardView not showing shadow elevation

前端 未结 17 1244
广开言路
广开言路 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 16:52

    Add this line in CardView widget

    app:cardElevation="5dp"
    

    hope this will help!

    0 讨论(0)
  • 2020-12-14 16:55
         <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardElevation="10dp"
        app:cardCornerRadius="4dp"
        app:cardBackgroundColor="#ffff8800">
         ......
         </android.support.v7.widget.CardView>
    

    Remove the background color first, add the elevation and later add the background again. Worked for me, though I had added the background through the layout designer.

    0 讨论(0)
  • 2020-12-14 16:58

    If your manifest file has a android:hardwareAccelerated="false" line, delete it.

    0 讨论(0)
  • 2020-12-14 16:58

    Try adding android:outlineProvider="bounds" to the CardView layout.

    0 讨论(0)
  • 2020-12-14 16:59

    You forget two things.

    • First of all, check your project's AndroidManifest.xml file, in the Application tag you have to write

    <application android:hardwareAccelerated="true" ...>

    instead of

    <application android:hardwareAccelerated="false" ...>

    1. Then check the parent tag of your layout file is there written like below line.

    2. if you wanna use app: xmlns. then write : xmlns:app="http://schemas.android.com/apk/res-auto"

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

    NOTE: You don't need to write both simultaneous. Because it gives you duplicate attribute error.

    The above line is most important when you use the attributes of res-auto.

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    
        <android.support.v7.widget.CardView
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardBackgroundColor="@android:color/white"
            app:cardCornerRadius="4dp"
            app:cardElevation="4dp" />
    
    </RelativeLayout>
    
    0 讨论(0)
  • 2020-12-14 16:59

    remove below line from AndroidManifest.xml

    android:hardwareAccelerated="false"
    
    0 讨论(0)
提交回复
热议问题