Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

Android ScrollView layout problem

I have several ListViews in a LinearLayout. It's listing things by day, so I have a TextView containing "Sunday:" followed by a list of items, followed by a "Monday" TextView, etc. Works great, but doesn't fit in the screen. So I added a ScrollView as a parent of the LinearLayout. Now it scrolls, but the ListViews all have room for 2 entries, whether they have 0 or 3 entries. Something about adding the ScrollView parent caused the ListViews to not size dynamically. I tried calling requestLayout() on the ScrollView after the list adapters had filled their views, but that didn't do anything. Any ideas?

Edit: From http://www.anddev.org/viewtopic.php?p=25194 and other links it seems that ListViews inside a ScrollView are not handled correctly. Anyone have a good suggestion for implementing a list-of-lists?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm interested in that topic too, so I did a bit of research. First: Never put a ListView in a ScrollView (as you found out yourself). Unfortunately googling this problem doesn't lead to any solutions, so I tried my suggestion from my comment above.

I implemented a custom ListAdapter and put the ListViews into one parent ListView. This doesn't work (leads to the same problem as with a ScrollView). Speaking to the guys on the official android-irc #android-dev on freenode, they told me that putting ListViews into a ListView is as bad as or even worse than putting them into a ScrollView. Unfortunately they also couldn't help me with the problem.

There seems to be only one way to achieve what you want to do; see the answer on this similar question Scrolling with Multiple ListViews for Android . The idea is to merge all ListViews into a single one by a custom adapter and to insert some kind of headers between entries. This is absolutely doable but might require some special effort.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...