views:

938

answers:

3

So my layout looks basically like this:

<ScrollView>
    <RelativeLayout>
        <BunchOfViews/>
        <ImageView android:layout_alignParentBottom="true"/>
    </RelativeLayout>
</ScrollView>

I have the ScrollView so all of the layout always is visible no matter the height of the screen. The problem is that on a very high screen, I still want my imageview to be at the bottom. However, a child of a ScrollView dont seem to have a defined bottom. The View is placed at the top of the layout. How can I solve this problem in a neat way?

Cheers,

A: 

From: http://code.google.com/p/k9mail/source/browse/k9mail/trunk/res/layout/account_setup_basics.xml?r=1314

This should help you:

<RelativeLayout
        android:layout_marginTop="-45dip" 
        android:padding="0dip"
        android:layout_alignParentBottom="true"
        android:gravity="bottom|right" 
        android:background="@android:drawable/bottom_bar"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent">
        <Button
            android:id="@+id/manual_setup"
            android:text="@string/account_setup_basics_manual_setup_action"
            android:minWidth="@dimen/button_minWidth"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginBottom="-4dip" 
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="false" 
            />
        <Button
            android:id="@+id/next"
            android:text="@string/next_action"
            android:minWidth="@dimen/button_minWidth"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:drawableRight="@drawable/button_indicator_next"
            android:layout_marginBottom="-4dip" 
            android:layout_alignParentRight="true"
            android:layout_centerVertical="false" 
            />
    </RelativeLayout>
Pentium10
Im sorry, but I dont think I was clear enough. I still want the imageview to be a part of the scrollview, as in my current layout. It should just be at the bottom of the scrollview. And if the scrollview is shorter then the screen, then the imageview should still be at the bottom of the screen.
sandis
Also I dont quite understand the effect of having negative numbers on the pixel numbers. I have never used these. So maybe I just have not understood what you were trying to say. If so, could you please elaborate? :P Thanks.
sandis
I don't understand why you need the scrollview if your content does not fill the screen. Using a `android:gravity="bottom|right" ` on a view should put on the bottom. The negative values probably are meant to cut off excessive padding inside button's layout.
Pentium10
+3  A: 

I ran into the same issue. I never could find a very pleasing solution, but here is how I did it. Maybe someone else has a better way, I hate adding layouts that don't do anything.

My hack was to add a dummy linearlayout at the bottom of the scrollview that has fill_parent to take up all the room and force the scrollview to fill the screen. Then add whatever component I want to that linearlayout.

Here is one of my layouts that does this:

<ScrollView
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:fillViewport="true"
    android:layout_weight="1">
    <RelativeLayout
      android:layout_height="fill_parent"
      android:layout_width="fill_parent"
      android:layout_marginTop="15px">

    ... bunch of components

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_marginTop="5px"
        android:paddingTop="2px"
        android:layout_below="@+id/spinner"
        android:layout_height="fill_parent"
        android:gravity="center_horizontal|bottom">

          <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Delete"
            android:paddingLeft="20px"
            android:paddingRight="20px" />
    </LinearLayout>
</RelativeLayout>

dweebo
Thanks, I finally got it. You have made my app so pretty! :)
sandis
+2  A: 

it seems that the linearlayout isn't necessary, all that is important is the fillViewPort. you could just use

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottomParent="true">

now that you have specified the relativelayout to be at least the size of the screen.

Laurent