How to Move LinearLayout to the Bottom of its Parent Layout in Android

In this android programming source code example, we are going to explore how to move LinearLayout to the bottom of its parent layout in android.

Below is a step by step source code to move LinearLayout to the bottom of its parent layout in android.

With LinearLayout as Parent Layout

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    android:orientation="vertical"
    tools:context=".layout.Layout12">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitEnd"
        android:src="@drawable/notebook" />

</LinearLayout>

With FrameLayout as Parent Layout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".layout.Layout12">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitEnd"
        android:layout_gravity="bottom"
        android:src="@drawable/notebook" />

</FrameLayout>

With RelativeLayout as Parent Layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".layout.Layout12">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:contentDescription="@string/app_name"
        android:scaleType="fitEnd"
        android:src="@drawable/notebook" />

</RelativeLayout>

Finally, if you want to achieve this programmatically by adding a View and position it at the bottom of its parent View, follow the link to our previous source code example.

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