tags:

views:

89

answers:

1

The problem I am having seems to be that if I have a view (e.g. myButton) inside a RelativeLayout set to alignParentBottom - (as per the code below) - and then wrap the RelativeLayout with a scrollview (necessary so the content will be viewable on smaller screens or when orientation changes to landscape) - then, when the parent bottom is NOT visible (for example when changed to landscape orientation) myButton is displayed at the TOP of the page - NOT the bottom.

How can you align a view to the bottom of the screen and have it remain at the bottom even if the bottom is below the scroll?

<ScrollView
android:id="@+id/mainScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true">



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



... lots of views and stuff


<Button android:layout_alignParentBottom="true" 
android:id="@+id/myButton"  
android:text="Click Me" />

</RelativeLayout>
</ScrollView>   
A: 

Using fill_parent as the height of a child of a ScrollView is meaningless. You are telling the RelativeLayout to be always as tall as its parent. In this case, the ScrollView becomes useless! The height of the RelativeLayout should be set to wrap_content, in which case, depending on what the RelativeLayout contains, alignParentBottom may not work as you expect. You should simply use a LinearLayout, it will be much much simpler.

Romain Guy
Well, I don't understand why you say the scrollview becomes useless, its function is to allow scrolling, and it does that...so I have to use it. I have to use RelativeLayout so that I can use android_alignParentBottom. I don't see how using LinearLayout would solve this because then I can't align myButton to the bottom of the screen. Is it just not possible to align a view to the bottom of the screen and support scrolling at the same time?
It's useless if the child has height=fill_parent. fill_parent means "I want to be as tall as my parent." So if the content of the ScrollView is as big as the ScrollView itself, it won't scroll.
Romain Guy
Ok. I appreciate your guidance. However, the layout does indeed scroll, that is not the problem I am trying to solve.
I am explaining why your layout doesn't work like you expect, because it can't by using fill_parent.
Romain Guy