Home » Android » android – How to make cardview show only bottom shadow

android – How to make cardview show only bottom shadow

Posted by: admin May 14, 2020 Leave a comment

Questions:

i use following code:

<android.support.v7.widget.CardView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardUseCompatPadding="true"
        app:cardElevation="4dp">
    <TextView android:text="in card view" android:layout_width="match_parent" android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>

the screenshot is:

enter image description here

how to make only bottom show shadow?

How to&Answers:

If you want a linear shadow, try this:

<View
    android:id="@+id/shadow"
    android:layout_width="match_parent"
    android:layout_height="3dp"
    android:background="@drawable/down_shadow"
    />

down_shadows.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >

    <gradient
        android:angle="-90"
        android:endColor="#EEEEEE"
        android:startColor="#FFFFFF"
        />

</shape>

See also different articles for manual setting of shadows like this: https://medium.com/@ArmanSo/take-control-of-views-shadow-android-c6b35ba573e9.