How to Show Shadow Around the Linearlayout in Android

Android LinearLayout : Add border with shadow around a LinearLayout

Try this..

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#CABBBBBB"/>
<corners android:radius="2dp" />
</shape>
</item>

<item
android:left="0dp"
android:right="0dp"
android:top="0dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:radius="2dp" />
</shape>
</item>
</layer-list>

How to show shadow around the linearlayout in Android?

There is no such attribute in Android, to show a shadow. But possible ways to do it are:

  1. Add a plain LinearLayout with grey color, over which add your actual layout, with margin at bottom and right equal to 1 or 2 dp

  2. Have a 9-patch image with a shadow and set it as the background to your Linear layout

How to create shadow effects just like shown below for linear layout in android?

Then Use 9 Patch image for that,

9 patch image

for more detail here is question for shadow LinearLayout

Add shadow to bottom of view

Try using below line in the linearlayout under which your cardview is sitting.

android:elevation="8dp"

Let the cardElevation part in your cardView be as it is.

card_view:cardElevation="10dp"
card_view:cardPreventCornerOverlap="false"

Also just a suggestion :

If you're using android:layout_weight in both child linearLayout put android:weightSum="2" in your parent linearLayout as mentioned in answer given by @Ming Leung here

For more information on android:weightSum="2" you can refer to answers on this page

This page would help you for elevation in cardview

Hope that helps.



Related Topics



Leave a reply



Submit