I am new to Android Development and learning ViewGroups
. So, I found it very strange that why we can't add more than one direct view or viewGroups in scrollview
?
Asked
Active
Viewed 162 times
0

Shoaib Kakal
- 1,090
- 2
- 16
- 32
-
Because Scrollview supports only one child in it – Jaimil Patel Apr 18 '20 at 13:01
-
Then what's wrong if Scrollview supports multiple childs in it? – Shoaib Kakal Apr 18 '20 at 13:05
-
It shows error because you have to implement only one child in it but that child can contain number of child so there is no any problem – Jaimil Patel Apr 18 '20 at 13:07
-
Sorry but that's what I am asking. what is the logic behind this error like why android implemented this restriction, there should be any strong concept for not using direct multiple views in it. – Shoaib Kakal Apr 18 '20 at 13:14
1 Answers
1
Well why not add one viewgroup like (LinearLayout) to your scrollView and then add the views into this viewgroup.
You can always use a RecyclerView which is the best approach for different view types in a list.

Hasan Bou Taam
- 4,017
- 2
- 12
- 22
-
Yes, we can do it by one `LinearLayout` but again why we are restricted to use only one view or ViewGroup?.I only need a textView to show long paragraphs and a comment button at the end So, here using RecyclerView makes no sense. – Shoaib Kakal Apr 18 '20 at 14:59
-
-
You can use a FrameLayout, where the scrollview having only textview is added first and then on top of that add the button such that it is at the end (so the button float on the scroll view). – Hasan Bou Taam Apr 18 '20 at 15:02
-
But I don't why not just include a linear layout inside the scroll view? – Hasan Bou Taam Apr 18 '20 at 15:03