我有一个非常复杂的视图堆积,作为其中的一部分,我在scrollview中的线层中有一个listView(而且组件要多得多,但在这个问题上并不重要)。

现在,整个活动的滚动效果很好,但是ListView的高度有限,当它内部的项目超过高度时,我的屏幕消失了。我试图将ListView放入其自己的ScrollView中,但这无效。当我尝试在listView上滚动时,选择了主滚动视图,而我的屏幕滚动而不是listView。

我的问题听起来很容易,但是我无法解决此问题...是否可以使listView滚动同时使用?

相关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>
有帮助吗?

解决方案 2

实际上,我设置的方式确实在工作...将listView放在scrollview中的线层中。只需避免ListView是ScrollView的直接孩子,它将很好地工作...

请注意,如果ListView中没有足够的项目来填充它,以使其“离屏幕”,则不会滚动(虽然从逻辑上讲是一种)。另请注意,当您有足够的项目可以滚动时,您需要继续按下ListView中的项目以使其滚动,并且一半的时间将重点放在全局scrollview,而不是listView ...避免(大多数情况下),根据您要滚动的方式,请继续按下最高或大多数的项目。这将优化您将重点放在listView上的机会。

我制作了一个视频,说这是可能的,现在将其上传到YouTube ...

视频是 http://www.youtube.com/watch?v=c53oig_3lky. 。质量有点糟糕,但这证明了我的意思。

只是为了进行全局概述,我使用scrollview能够滚动我的整个活动,活动布局的线安排以及listView,to to to to your stay list ...

其他提示

ScrollView中的其他布局不用ListView与标题和页脚创建一个ListView。

添加应在ListView上方作为标头的视图:

addHeaderView(View v)

在下面的页脚:

addFooterView(View v)

将所有内容放在ListView上方的所有内容上,并将其与页脚相同。

    LayoutInflater inflater = LayoutInflater.from(this);
    mTop    = inflater.inflate(R.layout.view_top, null);
    mBottom = inflater.inflate(R.layout.view_bottom, null);

    list.addHeaderView(mTop);
    list.addFooterView(mBottom);
    // add header and footer before setting adapter
    list.setAdapter(mAdapter);

结果,您将获得一个可滚动视图。

尝试此代码可能会帮助您

        ListView listView = ( ListView ) findViewById(R.id.lsvButton3);
        listView.setOnTouchListener(new ListView.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                switch (action) {
                    case MotionEvent.ACTION_DOWN:
                        // Disallow ScrollView to intercept touch events.
                        v.getParent().requestDisallowInterceptTouchEvent(true);
                        break;

                    case MotionEvent.ACTION_UP:
                        // Allow ScrollView to intercept touch events.
                        v.getParent().requestDisallowInterceptTouchEvent(false);
                        break;
                }

                // Handle ListView touch events.
                v.onTouchEvent(event);
                return true;
            }
        });

我想注意视频

listView每x都可以使用一次,不是因为您将其放置在线安装中,而是因为您正在触摸分隔线...

然后,ScrollView将考虑您触摸的地方没有孩子将MotionEvent派遣到...因此,它称为Super.disPatchTouchEvent,在这种情况下为view.dispatchtouchview,因此listview.ontouchevent。

当您触摸一排时,ScrollView确实是一个ViewGroup,将调度发送给您的孩子,在您的情况下,文本视图,从不调用视图之一,因此listView不要滚动。

希望我的解释足够明确,可以指出为什么不起作用。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top