如何使用ListView控件作为滚动型的孩子之一 [英] How do I use ListView as one of the children of a ScrollView
问题描述
我已经阅读了许多文献是说,不这样做的。但他们还没有提供一种替代的解决方案。这个问题似乎来了很多,虽然。这里是我的问题。
I have read a number of literatures that say not to do this. But they have yet to offer an alternative solution. The question seems to come up a lot, though. Here is my problem.
-
我想我的主要布局是滚动(这是因为它具有比可以适应屏幕更多的意见)。我主要布局是垂直的LinearLayout。所以现在我有它里面滚动型
I want my main layout to be scrollable (this is because it will have more views than can fit the screen). My main layout is a vertical LinearLayout. So for now I have it inside a ScrollView.
我的LinearLayout的许多孩子之一,是一个ListView(显示3项,用户滚动ListView的更多)。
one of the many children of my LinearLayout is a ListView (shows 3 items, user scrolls the ListView for more).
可以像我的LinearLayout的其他孩子是什么将说服你,我需要这个工作:例如,可以是一个滚动的水平的LinearLayout;另一个可能是一个ViewPater;等等。
You can image the other children of my LinearLayout to be whatever will convince you that I need this to work: for example, one may be a scrollable horizontal LinearLayout; another may be a ViewPater; etc.
现在如果我的LinearLayout的内容可以一下子适应屏幕,我也没问题。但是,我有我的LinearLayout大约六个不同的孩子,只有约三在同一时间是可见的。所以,是的,我确实需要能够滚动我的LinearLayout。
Now if the content of my LinearLayout could all fit the screen at once, I would have no problem. But I have about six different children in my LinearLayout and only about three are visible at one time. So, yes, I do need to be able to scroll my LinearLayout.
一件事。如果我滚动孩子ListView和我到达终点,我需要家长的LinearLayout重新开始控制,并开始滚动作为用户滚动。
One more thing. If I am scrolling the child ListView and I reach the end, I need the parent LinearLayout to resume control and start scrolling as user scrolls.
澄清
澄清一点的是,我的ListView实际上是动态添加到一个ViewPager。因此从技术上讲,一个ViewPager是我的LinearLayout的孩子。但随后ViewPager内,其中一个页面是一个ListView。
One clarification is that my ListView is actually dynamically added to a ViewPager. So technically, a ViewPager is the child of my LinearLayout. But then inside the ViewPager, one of the pages is a ListView.
注意
顺便说一句,我看了滚动型内滚动的ListView。答案有好的,但我仍然有一些问题。
By the way, I have read scrolling ListView within ScrollView. The answer there is good, but I still have a few problems.
-
在ListView控件的边缘达到控制不会恢复到滚动型
once edge of ListView is reached control does not revert to ScrollView
如果任何的LinearLayout的其他子视图点击监听器,那么我不能用它们来滚动滚动型。所以基本上大部分屏幕,滚动视图不滚动的。
If any of the other child views of the LinearLayout have a click listener, then I cannot use them to scroll the ScrollView. So basically for most of the screen, the scroll view is not scrollable.
推荐答案
您可以使用的ListView
为主要布局(而不是滚动型
),并把上面的意见与列表 addHeaderView()
-method(以分组的的LinearLayout
或类似的东西),并做下面的列表中的项目一样,用 addFooterView
的的ListView -method
。
You could use the ListView
as main layout (instead of the ScrollView
) and put the views on top with the lists addHeaderView()
-method (grouped in a LinearLayout
or something like that) and do the same with the items below the list, with the addFooterView
-method of the ListView
.
我没有测试它,但我认为它可能工作。
I did not test it, but I think it might work.
这篇关于如何使用ListView控件作为滚动型的孩子之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!