如何让我的 ListView 滚动? [英] How can I get my ListView to scroll?

查看:25
本文介绍了如何让我的 ListView 滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常复杂的视图构建,作为其中的一部分,我在 ScrollView 的 LinearLayout 中有一个 ListView(还有更多的组件,但它们在这个问题上无关紧要).

I have a quite complex View build-up, and as a part of that, I have a ListView inside a LinearLayout within a ScrollView (and quite a lot more components, but they do not matter in this issue).

现在整个 Activity 滚动得很好,但是 ListView 的高度有限,当它里面的 Items 超过高度时,我的屏幕就会消失.我试图将 ListView 放在它自己的 ScrollView 中,但这不起作用.当我尝试在 ListView 上滚动时,主 ScrollView 被选中并且我的屏幕滚动而不是 ListView.

Now the whole activity scrolls nicely as it should, but the ListView has a limited height, and when the Items inside it surpass the height, the disappear of my screen. I've tried to place the ListView inside it's own ScrollView, but this doesn't work. When I try to scroll on the ListView, the main ScrollView is selected and my screen scrolls instead of the ListView.

我的问题听起来很简单,但我一直没能解决这个问题...是否可以使 ListView 也可滚动?

My question may sound easy, but I haven't been able to fix this... Is it possible to make the ListView scrollable aswell?

相关的 XML:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

    <LinearLayout android:id="@+id/GlobalLayout" 
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:orientation="vertical" >

        <ListView android:id="@+id/EndpointList"
                  android:choiceMode="multipleChoice"
                  android:layout_height="175dip"
                  android:layout_width="fill_parent" />

    </LinearLayout>

</ScrollView>

推荐答案

实际上,我设置它的方式确实有效……将 ListView 放置在 ScrollView 内的 LinearLayout 中.只要避免 ListView 是 ScrollView 的直接子项,它就会很好地工作......

Actually, the way that I have it set up is really working... Placing a ListView in a LinearLayout within a ScrollView. Just avoid that the ListView is the direct child of the ScrollView, and it will work out just fine...

请注意,如果 ListView 中没有足够的项目来填充它,因此它会离开屏幕",它就不会滚动(虽然有点合乎逻辑).另请注意,当您有足够的项目可以滚动时,您需要持续按下 ListView 中的一个项目以使其滚动,并且有一半的时间,焦点是全局滚动视图而不是 ListView...避免这种情况(大多数情况下),继续按下最顶部或最下方的项目,具体取决于您要滚动的方式.这将优化您将注意力集中在 ListView 上的机会.

Just be aware that if there aren't enough items in the ListView to fill it so it goes 'off screen', that it won't scroll (kind of logically though). Also note that when you have enough items to scroll through, you need to keep pressing on an item in the ListView to make it scroll, and half of the time, focus is given to the global scrollview in stead of the ListView... To avoid this (most of the time), keep pressing on the most top or most down item, depending on which way you want to scroll.This will optimize your chance to get focus on your ListView.

我已经制作了一个视频,现在正在上传到 YouTube...

I've made a video that it is possible, am uploading it now to YouTube...

视频是http://www.youtube.com/watch?v=c53oIg_3lKY.质量有点差,但它证明了我的观点.

Video is http://www.youtube.com/watch?v=c53oIg_3lKY. The quality is kinda bad, but it proves my point.

只是为了全局概览,我使用 ScrollView 来滚动我的整个 Activity,使用 LinearLayout 用于 Activity 的布局,使用 ListView 来制作列表...

Just for a global overview, I used the ScrollView to be able to scroll my entire activity, the LinearLayout for the Activity's layout, and the ListView to, well, make the list...

这篇关于如何让我的 ListView 滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆