How to set content in a Linear layout to the BOTTOM of the Screen in Android.?

android

Solution

You should use RelativeLayout, Look for example

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

    <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffff0000"
        android:layout_above="@+id/bottom_panel">

    </ScrollView>

    <LinearLayout 
        android:id="@+id/bottom_panel"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <Button 
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="Button 1"/>

        <Button 
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="Button 2"/>

        <Button 
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="Button 3"/>

        <Button 
            android:layout_width="0dip"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="Button 4"/>
    </LinearLayout>

</RelativeLayout>

This will give you something similar. Just place your widgets instead of my buttons.

Problem

See the following XML code ``` <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <include layout="@layout/header" /> <TextView android:layout_width="fill_parent" android:layout_height="18dp" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/header" android:orientation="horizontal" > <ImageView android:layout_width="50dp" android:layout_height="50dp" android:src="@drawable/calendar" /> <TextView android:id="@+id/tvTitle" android:layout_width="fill_parent" android:layout_height="50dp" android:gravity="center" android:text="@string/calendar" android:textColor="#FFFFFFFF" android:textSize="18sp" /> </LinearLayout> <LinearLayout android:id="@+id/myLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > </LinearLayout> <!-- <include layout="@layout/footer"/> --> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="@drawable/datename_bottom_bg" android:orientation="horizontal"> <TextView android:id="@+id/upgrade_4" android:layout_width="50dp" android:layout_height="50dp" android:layout_weight="1" android:drawableTop="@drawable/upgrade" android:gravity="center" android:text="@string/upgrade" android:textSize="8sp" /> <TextView android:id="@+id/panchang_4" android:layout_width="50dp" android:layout_height="50dp" android:layout_weight="1" android:drawableTop="@drawable/kalash_bottom" android:gravity="center" android:text="@string/panchang" android:textSize="8sp" /> <TextView android:id="@+id/time_range_4" android:layout_width="50dp" android:layout_height="50dp" android:layout_weight="1" android:drawableTop="@drawable/timer_bottom" android:gravity="center" android:text="@string/timespan" android:textSize="8sp" /> <TextView android:id="@+id/reminder_4" android:layout_width="50dp" android:layout_height="50dp" android:layout_weight="1" android:drawableTop="@drawable/reminder_bottom" android:gravity="center" android:text="@string/reminders" android:textSize="8sp" /> <!-- <TextView android:id="@+id/calendar_4" android:layout_width="50dp" android:layout_height="50dp" android:drawableTop="@drawable/calendar_bottom" android:text="@string/calendar" android:textSize="8sp" android:gravity="center" android:layout_weight="1"/> --> </LinearLayout > </LinearLayout> </ScrollView> ``` What this looks like is on the left and what I want it to look like is on the right, I also tried it by replacing LinearLayout to RelativeLaout but still not working. Please Help.!

Original source