Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm trying to give elevation to corners of cardview

I'm trying to provide elevation to the corners of cardview. my requirement is elevation should n't effect at the middle of cardview. it should effect only corners like image shown below.

As shown in image, at the middle of the cardview elevation should be zero at corners there should be some elevation (for example: elevation:4dp)

Here is the code i tried so far

 <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="10dp"
                                            android:layout_marginRight="10dp"
                                            android:layout_marginTop="10dp"
                                            android:background="@null"
                                            android:gravity="center"
                                            card_view:cardBackgroundColor="@android:color/white"
                                            card_view:cardCornerRadius="4dp"
                                            card_view:cardElevation="3dp">
like image 951
Naga Lokesh Kannumoori Avatar asked Oct 17 '25 00:10

Naga Lokesh Kannumoori


1 Answers

Try setting card_view:cardUseCompatPadding="true"

So your xml should look like:

<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="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:background="@null"
            android:gravity="center"
            card_view:cardBackgroundColor="@android:color/white"
            card_view:cardUseCompatPadding="true"
            card_view:cardCornerRadius="4dp"
            card_view:cardElevation="3dp"/>
like image 137
mrid Avatar answered Oct 19 '25 14:10

mrid