Eugene
Eugene

Reputation: 60184

How to stick a view at the bottom of the screen so the above part is movable?

My layout consists of a ScrollView which holds everything. At some point I need to show a View at the bottom of the screen on top (above) of ScrollView (so ScrollView goes behind the View) so I could scroll the screen up and down while this View still be sticked to a device's screen bottom. Please advice guys how to do such a layout. Thank you.

Upvotes: 2

Views: 3840

Answers (3)

NickL
NickL

Reputation: 4276

If you want the scrollview to go behind the view, this can be done like this:

(partial code copy from this SO question)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/RelativeLayout1">

        <ScrollView android:id="@+id/scrollView"  
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
        </ScrollView>

        <View android:id="@+id/bottomView" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_alignParentBottom="true"
            android:visibility="gone">>
        </View>
</RelativeLayout>

The scrollview will now expand beyond the View element.

Upvotes: 4

reVerse
reVerse

Reputation: 35254

Okay two options, first one:

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

<View
    android:id="@+id/myView"
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:layout_alignParentBottom="true" />

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/myView" />

</RelativeLayout>

This way your ScrollView will always be above of your View. But it seems like you want the ScrollView to fill the whole screen while the View "hides" some of the items of your SV. So check this code:

<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="wrap_content"/>

 <View
    android:id="@+id/myView"
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:layout_alignParentBottom="true" />

</RelativeLayout>

Upvotes: 0

Marcin S.
Marcin S.

Reputation: 11191

You could create two fragments and use the weight attribute to distribute the space. The fragment at the top would host you root scrolView and the fragment at the bottom would have the View.

Upvotes: 1

Related Questions