How to Add Border With Shadow Around a LinearLayout in Android

In this android programming source code example, we going to explore how to add border with shadow around LinearLayout in android.

Below is a step by step source code to add border with shadow around LinearLayout in android.

activity_layout4.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:background="@drawable/linear_layout_border_shadow"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:context=".layout.Layout4">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Border Shadow"
        android:padding="5dp"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:src="@drawable/notebook" />

</LinearLayout>

drawable/linear_layout_border_shadow.xml

<?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:bottom="5dp" android:left="2dp" android:right="2dp" android:top="5dp">
                <shape android:shape="rectangle">
                    <solid android:color="#FFFFFF" />
                    <corners android:radius="2dp" />
                </shape>
            </item>
        </layer-list>
    </item>
</selector>

Layout4.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class Layout4 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout4);
    }
}

If you have any question or suggestions kindly use the comment box or you can contact us directly through our contact page below.

 

Add a Comment