Only one view can be included in a ScrollView .
fillViewport allows scrollView to extend it's height equals to the full height of device screen's height in the cases when the child of scroll view has less height.
A view group that allows the view hierarchy placed within it to be scrolled. Scroll view may have only one direct child placed within it. To add multiple views within the scroll view, make the direct child you add a view group, for example LinearLayout , and place additional views within that LinearLayout.
Try adding android:fillViewport="true"
to your ScrollView
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 aScrollView
. After all, theScrollView
would become useless if its content was always as tall as itself. To work around this, you need to use the ScrollView attribute calledandroid:fillViewport
. When set to true, this attribute causes the scroll view’s child to expand to the height of theScrollView
if needed. When the child is taller than theScrollView
, the attribute has no effect.
http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
Just add android:fillViewport="true" in yout xml layout in Scrollview
<ScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/green"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fitsSystemWindows="true"
android:fillViewport="true"
>
<!--define views here-->
</ScrollView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With