1

I have a Scrollview for the complete screen, so in small phones you can scroll and see the complete form.

For big screen/hdpi phones, the screen has enough size so it fits.

The problem is that since its a LinearLayout, all views are at the top, and there is white space at the bottom.

I set the weight on one of the items items inside the linear layout, but it does not grow.

my code:

  <ScrollView>
       <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <RelativeLayout
                 android:id="@+id/header"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:orientation="vertical" >
                 HEADER STUFF
            </RelativeLayout>


             <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical" > 
           THIS PART I NEED TO GROW AS MUCH AS POSSIBLE SO THE FOOTER IS AT THE BOTTOM OF THE PAGE.
          </RelativeLayout>


        <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/LightBlue"
        android:orientation="vertical"
        android:paddingBottom="10dp" >
            FOOTER STUFF.  NEED THIS TO BE AT THE FOOTER IF THE PHONE IS BIG ENOUGH. 
            </RelativeLayout>
       <LinearLayout>
</ScrollView>
Daniel Benedykt
  • 6,496
  • 12
  • 51
  • 73
  • 2
    U need to put ScrollView in middle layout(Relative) and fix the header and footer layout height.So that if your middle layout content more then it will wrap and will not affect neither header nor footer. – TheFlash Jul 24 '14 at 02:43
  • This is a very good solution, but does not cover all cases (but covers lots of cases). For example, if the header or the footer are both big enough that they almost meet in the middle on the screen (when using a small phone) the user will not have enough space to scroll, where if the whole screen scrolls, then it wouldn't be a problem. – Daniel Benedykt Jul 24 '14 at 03:30
  • put different header and footer size in value folders (value-large,value-small,value-sw320dp,value-sw320dp-hdpi,value-v11,value-v14 etc) It will solve ur problem. – TheFlash Jul 24 '14 at 03:33
  • weight in never work when parent layout as ScrollView. – Haresh Chhelana Jul 24 '14 at 04:37
  • Indiandroid, Now the problem is that when the keyboard opens to fill the form, the footer moves up to the top of the keyboard, and it takes some screen space. Is it possible to avoid it ? – Daniel Benedykt Jul 24 '14 at 15:31
  • possible duplicate of [View inside ScrollView doesn't take all place](http://stackoverflow.com/questions/10211338/view-inside-scrollview-doesnt-take-all-place) – corsair992 Jan 01 '15 at 17:59

1 Answers1

-1

Simple answer: In the LinearLayout, change android:layout_height="wrap_content" to android:layout_height="match_parent".

Reason: By wrapping the content, you aren't giving the middle RelativeLayout with the most weight a chance to grow and fill the white space. Changing it to match the parent height gives it its space to blossom, so to speak.

Also, per Indiandroid's comment, you may want to put the ScrollView inside the LinearLayout and around the middle RelativeLayout that hosts the content so that the header and footer are fixed.

EDIT: If you intend to stretch the middle RelativeLayout by using weight in the LinearLayout, you will, after applying my previous part about switching the height to match_parent, have to move to ScrollView inside the LinearLayout around the middle RelativeLayout or it will grow indefinitely. This is because the ScrollView has no vertical bounds and by matching it's height with the LinearLayout, the LinearLayout also has no bounds.

  • If you change the `layout_height` to `match_parent` the scrollview can't stretch, the height will be fixed, so there won't be any scroll – Ibrahim Yildirim Jul 24 '14 at 03:23
  • No, it will have indefinite height as the ScrollView is the LinearLayout's parent and the ScrollView has no bounds. See my edit to my answer. – Samuel Rabinowitz Jul 24 '14 at 17:04
  • The `fillViewport` attribute was designed for just this purpose. See Romain Guy's blog post on it: http://www.curious-creature.com/2010/08/15/scrollviews-handy-trick. Your answer is not correct, as explained there. – corsair992 Jan 01 '15 at 18:01