2012年3月3日 星期六

[AndroidLayout] ScrollView handy trick by Romain Guy

Set the android:layout_weight of the TextView to 1.0. By doing so I am forcing the text to use the available empty space when it is shorter than the ScrollView. This can only work when android:fillViewport="true" is set on the scroll view.

To understand this result, you must remember that android:layout_height="fill_parent" means "set the height to the height of the parent." This is obviously not what you want when using a ScrollView.

After all, the ScrollView would become useless if its content was always as tall as itself. To work around this, you need to use the ScrollView attribute called android:fillViewport. When set to true, this attribute causes the scroll view’s child to expand to the height of the ScrollView if needed. When the child is taller than the ScrollView, the attribute has no effect.

fill_parent is meaningless inside a ScrollView. What you want is to use wrap_content and add android:fillViewport="true" on the ScrollView.


* Reference
- ScrollView’s handy trick – Romain Guy

沒有留言:

張貼留言