Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make cardview show only bottom shadow

Tags:

android

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?

like image 325
chikadance Avatar asked Jun 09 '16 04:06

chikadance


People also ask

How do I customize my CardView?

Customized CardView First, add a CardView dependency to the application-level build. gradle file. Then create a drawable background for the cards. For that, create a new drawable resource file inside the drawable folder.

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. To avoid moving the View while shadow size is changing, shadow size is clamped by getMaxCardElevation .

When should I use CardView?

CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other. The main usage of CardView is that it helps to give a rich feel and look to the UI design.


1 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_shadow.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.

like image 156
CoolMind Avatar answered Sep 19 '22 09:09

CoolMind