I have LinearLayout whcih contains Buttons and ListViews. After getting many buttons and I decide to put that LinearLayout into ScrollView but after putting ScrollView my Li
There is a conflict between the ScrollView
and the ListView
. In general, you cannot put a ListView
inside a ScrollView
. ListView
already understands about scrolling and will scroll itself. ListView
needs to know how much vertical space on the screen it should use, so that it can control the scrolling and display of its children. It is difficult to understand how the layout that you've posted should behave.
In any case, the only way to put a ListView
inside a ScrollView
is to tell the ListView
exactly how much vertical space it should use. You cannot use match_parent
or wrap_content
for layout_height
, you need to fix the vertical size. This helps the ScrollView
to determine how much vertical space each of its children takes up, and then the ScrollView
can do the right thing.
Try setting android:layout_height="80dp"
on all of your ListView
s to see how this behaves.
EDIT: After looking at the layout again, I have another suggestion
After looking at the layout again, I am assuming that you want to have only one of the ListView
s visible at a given time (the others would all be GONE). In this case, you might try the following:
ScrollView
android:layout_weight="1"
and android:layout_height="1px"
on all ListView
sThis basically tells the layout manager that the ListView
should be given all available space on the screen (ie: whatever is left over after the other View
s are laid out). This will make the ListView
expand to take up all available space on the screen, while keeping all the other View
s on screen and the entire screen will not scroll, only the ListView
. This may be a better way to give you what you want.
You might also consider using ExpandableListView
, which seems to be what you are trying to recreate here.