ScrollView distrubing ListView inside of LinearLayout

后端 未结 5 2014
长发绾君心
长发绾君心 2021-01-19 07:00

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

相关标签:
5条回答
  • 2021-01-19 07:05

    Try changing the android:layout_width="wrap_content" to android:layout_width="match_parent" o listview.

    0 讨论(0)
  • 2021-01-19 07:09

    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 ListViews 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 ListViews visible at a given time (the others would all be GONE). In this case, you might try the following:

    1. Remove the surrounding ScrollView
    2. Set android:layout_weight="1" and android:layout_height="1px" on all ListViews

    This 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 Views are laid out). This will make the ListView expand to take up all available space on the screen, while keeping all the other Views 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.

    0 讨论(0)
  • 2021-01-19 07:09

    http://www.londatiga.net/it/programming/android/make-android-listview-gridview-expandable-inside-scrollview/

    Go through the above link it might be helpful. OR follow below link as well.

    http://www.androidhub4you.com/2012/12/listview-into-scrollview-in-android.html

    0 讨论(0)
  • 2021-01-19 07:11

    Do one thing try giving hard coded height to your listview for example android:layou_height="100dp" and it will work but this is not recommended.

    0 讨论(0)
  • 2021-01-19 07:22

    You can not have directly or indirectly a ListView inside a ScrollView. That's because they will figth to manage touch events. You have to re-think about your UI design

    0 讨论(0)
提交回复
热议问题