tags:

views:

25

answers:

3

I'm new to android development... while making my application layout i want a button to remain at the very bottom of the screen while a scroll view is placed above it. I am unable to do this i was using the size of the scroll view as 430dp so that it works but when i change the orientation of the screen this does not work as 400dp is bigger than the screen. how do i make it so that the button stays at the bottom irresepective of the screen orientation ? :/

A: 

You could go with this

android:gravity="bottom"

This should always push your element to the bottom of its container.

But it'd more helpful if you'd post up your layout XML.

Octavian Damiean
+1  A: 

Set the ScrollView's layout_height to fill_parrent and layout_weight to 1 and the Button's height to wrap_content.

fhucho
A: 

Here's a real world example of precisely what you're asking. In this layout, I have a header at the top, a list view taking all the space below it and a button to clear (cancelled, failed, finished) elements of the list view, then right at the bottom I have a custom control showing a toolbar.

<?xml version="1.0" encoding="utf-8"?><LinearLayout android:id="@+id/layout" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">

<LinearLayout android:id="@+id/browsePeerHeader"
    android:layout_width="fill_parent" android:layout_height="70sp"
    android:layout_marginBottom="2sp"
    android:layout_gravity="top"
    android:background="@drawable/background_barbed_wire"
    >


    <ImageButton
        android:id="@+id/frostwire_sphere"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/icon"
        android:layout_gravity="center_vertical"
        android:layout_margin="3sp" 
        android:background="#00000000"/>

    <TextView android:id="@+id/browsePeerTitle" android:textSize="30sp"
        android:text="Downloads"
        android:textColor="#ffffffff" android:textStyle="bold" 
        android:shadowColor="#ff000000"
        android:shadowDx="1.0"
        android:shadowDy="1.0"
        android:shadowRadius="4.0"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:paddingTop="10sp"
        android:gravity="left|center_vertical"/>
</LinearLayout>


<ListView android:id="@+id/ListViewTransfers"
    android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
    android:layout_marginTop="2sp" 
            android:layout_marginBottom="2sp"
    android:layout_weight="1"></ListView>

<Button android:id="@+id/ButtonClearFinished" margin="2sp"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
 />

     <com.frostwire.android.views.FrostWireStatusBar
    android:id="@+id/FrostWireStatusBar" android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom" /></LinearLayout>

Here's a screenshot alt text

The trick is basically to have the list view use all the space left in the layout that contains it, you don't even have to tell it to fill_parent, just with android:layout_weight="1 it should work.

Gubatron