• Android linearlayout border shadow

    Android does not provide any attribute of the LinearLayout to add shadow to its border. However, it does not mean that it is impossible to achieve this goal. In case that you need to add border shadow to the LinearLayout, this Android tip is useful to you.
    To add the border shadow to the LinearLayout, you use a layout-list object. In the layout-list object, you will have two items (bottom and top items). The bottom item must be defined first in the layout-list. Its background is near gray color. It does not have spaces at its four corners. The top item that is defined last in the layer-list object has white background color. It has spaces at its four corners as you see in the xml code below. If you need to add shadow to the top and bottom borders only, simply assign zero to the android:left and android:right attributes. The xml code is saved in a file called bordershadow.xml in the drawable directory.
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
       <item>
       <layer-list>
          <item>
            <shape android:shape="rectangle">
               <solid android:color="#44D1D1D1"/>
               <corners android:radius="2dp" />
            </shape>
          </item>
          <item android:left="2dp" android:right="2dp" android:top="5dp" android:bottom="5dp">
            <shape android:shape="rectangle">
               <solid android:color="#FFFFFF"/>
               <corners android:radius="2dp" />
            </shape>
          </item>
       </layer-list>
       </item>
    </selector> 


    

    Now the border shadow you open the activity_main.xml file and add the background attribute to the Linearlayout. The value of the attribute will be @drawable/bordershadow.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:orientation="horizontal"
       android:padding="10dp"
       tools:context=".MainActivity"
       android:background="@drawable/bordershadow"
      >
       <Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Button"
          android:padding="5dp"
          />
       <Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Button"
          />
    </LinearLayout>



    linearlayout border shadow
  • 0 comments:

    Post a Comment

    FAVOURITE LINE

    To steal ideas from one is plagiarism. To steal from many is Research.

    ADDRESS

    Mumbai , Maharashtra

    EMAIL

    shikha.pathak6@gmail.com
    shikha.the.swt.pari@gmail.com

    Skype

    shikha_pari