简体   繁体   中英

Expandable Height of a List in Android

I'm having some problems writing a program that adds to a list dynamically at runtime. The program has some things above the list and the idea is that the user scrolls down to see the list that the program generates based on the user's input. However, when I use a list it is impossible for the user to see the lower parts of the list because the list takes up a set amount of space and if you try to scroll, the parent ScrollView takes over and assumes that you are trying to scroll the entire activity.

Is there a way to make the List height expand dynamically to wrap the children that are added so that the user can see all of the items in the list? I have tried setting the height to wrap_content, but that did not work. Any help is appreciated. Thanks.

I think you want to include a ListView within eg a LinearLayout

<LinearLayout ..
  android:orientation="vertical">
  <ViewOfUpperPart ... />
  <ListView ... />
</LinearLayout>

For the list itself you need an adapter that defines the individual list cell size and something like an OnScrollListener that is able to add more items to your ListView when the user scrolls down. See eg https://github.com/pilhuhn/ZwitscherA/blob/master/src/de/bsd/zwitscher/TweetListActivity.java#L295

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM