[android-developers] Re: ScrollView occupies entire screen height?
Mark Wyszomierski wrote:
> I'm having trouble with this layout - I need a ScrollView, then a
> LinearLayout with a button below that:
>
> <ScrollView height="fill_parent">
> </ScrollView>
> <LinearLayout height="wrap_content">
> <Button>
> <Button>
> </LinearLayout>
I am assuming the whole thing is being wrapped in a LinearLayout for my
comments below.
> the scrollview pushes the linear layout under it off the screen.
That's because you told it to via android:layout_height="fill_parent".
> The
> only way I can get this to work is if I explicitly set the scrollview
> height in pixels to be less than the total height of the screen, but
> hardcoding a height isn't going to work on different devices. How can
> I do this?
Set the ScrollView's android:layout_height="0px" and its
android:layout_weight="1". Android will allocate 0px initially to the
ScrollView, then however many pixels the LinearLayout needs. It then
divides the extra pixels between those widgets with weights; if the only
weight is on the ScrollView, it will "absorb" all those pixels.
Or, use a RelativeLayout to wrap the whole thing, anchoring the
LinearLayout to the bottom via android:layout_alignParentBottom="true"
and anchoring the ScrollView to the top
(android:layout_alignParentTop="true") and to the top of the
LinearLayout (android:layout_above="@id/whatever").
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
Android App Developer Training: http://commonsware.com/training.html
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home