What does fillViewPort in scrollView really do?

Viewed 18179

What is the benefit of fillViewPort?

In ScrollView, sometimes fillViewPort needs to be set to true so that the view gets displayed properly, and other times it's not needed at all.

And the documentations' description of it is not really clear

android:fillViewport

Defines whether the scrollview should stretch its content to fill the viewport.

3 Answers

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.

Thank for Hardik Parsania for this helpful post

Source of this sample : demonuts.com

fillViewport = “false”

enter image description here


fillViewport = “true”

enter image description here

fillViewport = true is advised for scrollViews containing a recyclerView that implements padding in the direction of the scroll (i.e. paddingBottom and/or paddingTop for vertical scrolling). Doing so, when paired with clipToPadding = false for the recyclerView, negates shrinkage of the viewport on scrolling to the point at which the recyclerView padding enters view.

Related