Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 818
ataulm Avatar asked Mar 07 '11 20:03

ataulm


2 Answers

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"

like image 162
Matthew Willis Avatar answered Sep 19 '22 18:09

Matthew Willis


It sounds like a bit of a troublesome layout to me (a mess :P)

But what I would say is play with the fillViewPort attribute, which will make the ScrollView take up the height available to it Android fillViewPort Docs

If you however want something similar to home screen I found out a way to force the view to take that exact height (See the stock Android news app, Tweetdeck or Admob [beta] for the sliding effect I'm referring to).

If this is the case let me know and I'll bung up some source code to do it.

like image 21
Matt Gaunt Avatar answered Sep 19 '22 18:09

Matt Gaunt