Android: Listview inside ScrollView

后端 未结 4 1894
抹茶落季
抹茶落季 2021-01-23 17:35

I want to have a layout that can scroll and a listview inside it. The listview will expand it\'s height base on how many items in it. Only the ScrollView outside is scrollable.

4条回答
  •  -上瘾入骨i
    2021-01-23 18:12

    Actually, it is possible to put a ListView inside of an ScrollView. In some use cases (e.g. dynamic menus/submenus it's a reasonable solution). However, two caveats apply:

    • The ListView won't have scroll. In general, nested scrolling is not possible in Android. There are some hacks to make it work (mostly by using requestDisallowInterceptTouchEvent()) but it's hard to make them work correctly in all cases.
    • As a consequence, you must indicate the exact height the ListView needs to show all items (via its appropriate LayoutParams). Setting WRAP_CONTENT will not work.

提交回复
热议问题