-1

If a layout is defining a ScrollView as a parent view and one of the children is a LinearLayout (vertical orientation with some children) is there a problem with this definition? Because I have seen sometimes that the linear layout is wrapped in another NestedScrollView so I was wondering what problem does that solve

Jim
  • 2,341
  • 1
  • 11
  • 23
  • It really depends what you're trying to do...examples would be helpful. – Ryan M Mar 13 '20 at 07:32
  • @RyanMentley: I am not trying to do something. I have seen it used and I was confused if that was redudant or there is some case that without it would break – Jim Mar 13 '20 at 07:45

1 Answers1

1

If you directly wrap a ScrollView in a NestedScrollView, and that is the only child of the NestedScrollView, that is redundant and unnecessary. If there are other children of the NestedScrollView, that may be correct, but then you probably would want both to be NestedScrollViews, in order to get consistent behavior across Android versions.

Ryan M
  • 11,512
  • 21
  • 38
  • 50
  • What about the reverse? I.e. Directly wrap a `NestedScrollView` inside a `ScrollView` as one of its (many) children? – Jim Mar 13 '20 at 08:04
  • 1
    In that situation, again, you probably would want both to be `NestedScrollView`s, in order to get consistent behavior across Android versions. – Ryan M Mar 13 '20 at 08:05
  • 1) Could you clarify what you mean by "consistent behavior across Android versions"? Both are part of the support library 2) If the LinearLayout (vertical) was the direct child of the root parent `ScrollView` what could be a problem there and we would need to instead make it a child of another (Nested)ScrollView? – Jim Mar 13 '20 at 08:09
  • 1
    `ScrollView` is not part of the support library (or the new version, `androidx`). Not having the two layers would be a problem if you wanted them both to be able to scroll separately in the same direction. If there's only one thing that scrolls, you don't need two layers. – Ryan M Mar 13 '20 at 08:11
  • So basically it solves the requirement of being able to have a "global" scroll for the full screen and a "local" scroll for the specific child? If that is the case, is that a normal android pattern? I think I have seen that only in mobile websites and not in apps – Jim Mar 13 '20 at 08:29
  • Basically, yes. A good example of nested scrolling in apps (though not implemented exactly this way) is a collapsing toolbar layout. – Ryan M Mar 13 '20 at 08:34