Sound Muter & Flashlight for Android

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

Posted by: Dara | post date: 05-03-2015 | Subject: Android Apps Development

write programming tip




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.