How to configure ListView to automatically change its height?

前端 未结 5 1653
梦毁少年i
梦毁少年i 2021-01-03 04:50

I have three ListView widgets in the same LinearLayout. Something like this (I\'m omitting XML elements that are not relevant in this example):

5条回答
  •  清歌不尽
    2021-01-03 05:45

    You can try iterating over the ListView's rows (see methods on ViewGroup), find their heights, sum them, and change your ListView height.

    That being said, I fully expect this to be awful:

    • You need to take into account the screen size, so your lists do not go past the bounds of the screen
    • You need to take into account orientation changes
    • You need to take into account any modifications to your data (e.g., deleting rows may require your list to shrink)
    • Etc.

    If your goal really is to have a single list, but you have three sources of data, merge the data and put it into a single list. My MergeAdapter can help here.

提交回复
热议问题