CardView not showing shadow elevation

前端 未结 17 1242
广开言路
广开言路 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:41

    The answer is a combination of margin and padding of cardView and its parent.

    Try like this:

        <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/minimum_dimem"
                android:layout_marginLeft="@dimen/default_margin"
                android:layout_marginRight="@dimen/default_margin"
                android:layout_marginTop="@dimen/minimum_dimem"
                app:cardBackgroundColor="@color/white"
                app:cardCornerRadius="@dimen/cardview_radius"
                app:cardElevation="@dimen/cardview_default_elevation">
    
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:padding="@dimen/ten_dimem">
    
                    ...
    
               </RelativeLayout>
    </android.support.v7.widget.CardView>
    

    And the result:

    0 讨论(0)
  • 2020-12-14 16:45
    <android.support.design.card.MaterialCardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:card_view="http://schemas.android.com/tools"
        app:cardCornerRadius="@dimen/_5sdp"
        card_view:cardCornerRadius="3dp"
        android:layout_margin="@dimen/_3sdp"
        card_view:cardElevation="10dp"
        card_view:cardUseCompatPadding="true">
    </android.support.design.card.MaterialCardView>
    

    Use above code and don't forget to use android:hardwareAccelerated="true". It will work definitely.

    0 讨论(0)
  • You should have to try this:

    <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            app:cardElevation="3dp">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
            </LinearLayout>
    
            <!--Put your other fields between this-->
    </android.support.v7.widget.CardView>
    
    0 讨论(0)
  • 2020-12-14 16:48

    There are two things that helped me solve this problem:

    1. Setting this in the application tag of my manifest:

      android:hardwareAccelerated="false"
      
    2. File > Invalidate cache and restart

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

    Try putting this in your rootview:

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

    and use this code for elevation:

    card_view:cardElevation="10dp"
    
    0 讨论(0)
  • 2020-12-14 16:52

    Do not forget that to draw shadow you must use hardwareAccelerated drawing

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

    see for details https://developer.android.com/guide/topics/graphics/hardware-accel.html?hl=ru

    0 讨论(0)
提交回复
热议问题