How can I put a similar effect to CSS box-shadow on a layout in Android?

3

Eg:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_marginTop="10dp"
    android:background="@drawable/bg_white"
    android:........ ?

>
</LinearLayout>

Like the OLX application:

    
asked by anonymous 05.02.2015 / 03:15

1 answer

6

This type of effect is well used in Material Design . It is based on CardView and / or RecyclerView .

I'll show you how easy it is to do this kind of effect.

  

drawable / layout_shadow_white.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#CABBBBBB"/>
            <corners android:radius="5dp" />
        </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="5dp" />
       </shape>
    </item>
</layer-list>
  

layout / my_layout.xml       

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:layout_below="@+id/relativeLayout"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="-20dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:background="@drawable/layout_shadow_white"
    android:id="@+id/rel_anything"></RelativeLayout>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:background="@drawable/layout_shadow_white"
    android:layout_below="@+id/rel_newgame"
    android:layout_centerHorizontal="true"
    android:id="@+id/rel_anything2"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp" />

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:background="@drawable/layout_shadow_white"
    android:id="@+id/rel_editor"
    android:layout_below="@+id/rel_culpado"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp" />

Usage: android:background="@drawable/layout_shadow_white"

  

Result

    
18.02.2015 / 20:59