Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a footer to scrollview

I have a scrollview containing a bunch of relative layouts which extends beyond the height of screen. How can I add a linearlayout with 2 buttons that "sticks" to the bottom of the screen. Meaning no matter how I scroll my scrollview, my linearlayout will always appear at the bottom of screen.

like image 969
Bkteo Avatar asked Mar 29 '11 09:03

Bkteo


2 Answers

<RelativeLayout
android:id="@+id/RelativeLayout01" 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
>
<ScrollView 
    android:id="@+id/my_scrollview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:layout_marginBottom="72dip"
    android:layout_above="@+id/LinearLayout01" 
    android:scrollbars="horizontal">

</ScrollView>
<LinearLayout 
    android:id="@+id/LinearLayout01" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_alignParentBottom="true">
    <Button 
        android:id="@+id/Button01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="1"">
    </Button>
    <Button 
        android:id="@+id/Button02" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </Button>
</LinearLayout>

like image 150
2red13 Avatar answered Oct 22 '22 23:10

2red13


You can realize this with RelativeLayout.

Your ScrollView should be placed above your button bar and below your header (when applicable).

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ScrollView
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_above="@+id/myFooter">
        <!-- Your scroll container -->
    </ScrollView>

    <RelativeLayout android:id="@+id/myFooter"
        android:layout_alignParentBottom="true" android:layout_height="wrap_content"
        android:layout_width="fill_parent">
        <!-- Your buttons -->
    </RelativeLayout>

</RelativeLayout>
like image 20
321X Avatar answered Oct 22 '22 23:10

321X