27

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 3

30

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

0
16

Source of this sample : demonuts.com

fillViewport = “false”

enter image description here


fillViewport = “true”

enter image description here

0
3

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.

1
  • 2
    According to documentation, its not advised to have a recycler view inside a scroll view - Never add a RecyclerView or ListView to a scroll view. Doing so results in poor user interface performance and a poor user experience. Commented May 7, 2023 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.