简体   繁体   中英

Android Card View Shadow in each side

I want to have same shadow on each side of card view like following image on both lollipop devices and above:

在此处输入图像描述

I hope this works for you. You can try using the app:cardElevation="8dp" attribute and change the value to suit your needs. Remember to add this attribute the parent layout first though xmlns:app="http://schemas.android.com/apk/res-auto"

example below

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:padding="10dp"
        app:cardCornerRadius="10dp"
        app:cardElevation="8dp">

    </androidx.cardview.widget.CardView>

</RelativeLayout>

As for the rounded corners you can use the app:cardCornerRadius="10dp" and adjust the value to suit your needs.

The key is use android:elevation="@dimen/_4sdp".

 <androidx.cardview.widget.CardView
    android:id="@+id/card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/_4sdp"
    android:background="@drawable/bg_white"
    android:elevation="@dimen/_4sdp"
    app:cardCornerRadius="@dimen/_8sdp">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM