Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cardview not showing shadow along bottom

I have the following xml for a cardview:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="2dp">
<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"
    android:layout_gravity="center"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="0dp">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dp">
        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </FrameLayout>
</android.support.v7.widget.CardView>
</LinearLayout>

Which results in these shadows which have no shading on the bottom at all

http://i.imgur.com/xNoIDR4.png

But I am trying to get something like this shadow, that more nicely surrounds the whole card.

enter image description here

I've tried changing the elevation to no avail, and searching on this issue seems to bring up nothing but people with no shadows at all issues which is not my case.

How can I get the shadows right?

Thanks.

like image 233
Zerp Avatar asked Apr 02 '15 15:04

Zerp


People also ask

How do I change the color of my shadow in CardView?

You need to use a drawable background ( shadow. xml ) in the parent layout which is looking like a shadow. You can replace FF46A9 in shadow. xml to change the color of shadow.

How do you set elevation in CardView?

To change CardView's elevation in a backward compatible way, use setCardElevation . CardView will use elevation API on Lollipop and before Lollipop, it will change the shadow size.


3 Answers

You need to add this xml property in your card view

app:cardUseCompatPadding="true"

like image 93
ch3tanz Avatar answered Oct 18 '22 01:10

ch3tanz


Adding clipChildren="false" to the parent LinearLayout should also work.

like image 38
Kavi Avatar answered Oct 18 '22 01:10

Kavi


set elevation using card_view:cardElevation property

like image 30
Varun Kumar Avatar answered Oct 18 '22 03:10

Varun Kumar