Search code examples
androidlayoutscrollview

ScrollView ignores child's layout_height


Got a LinearLayout containing a textview and an edittext. The LinearLayout is inside a ScrollView.

The ScrollView is inside another view hierarchy (part of a Work Space layout, like the Android Homescreen kinda), but this fills parent, both height and width (I set fill color different to check this).

With attributes of fill_parent for layout_height and layout_width on the LinearLayout though, it's only filling the parent width-ways, not height. Setting the height to fixed also doesn't work/ no effect. It's as if it's stuck on wrap_content, in effect.

In actuality, checking the hierarchy viewer, it's set to match_parent. Oddly, the weightsum of the LL is set to -1 (in the Hierarchy Viewer); the weightsum is not explicitly set.

If there's any further info I can supply to figure out why it's not honouring the layout_height attribute, let me know :)

Thanks in advance.


Solution

  • ScrollView has an infinite height (or height determined by the needs of its child), so layout_height="fill_parent" is not meaningful for views inside it.

    Edit - Romain Guy has an interesting article about this, and the solution is indeed to use fillViewport.

    Try setting it on the ScrollView itself in xml: android:fillViewport="true"