当用户在android中水平滚动时禁用垂直滚动

时间:2014-07-14 10:15:28

标签: android scroll custom-lists horizontallist

我有一个垂直自定义列表,垂直列表的每个项目都包含一个水平列表视图。当我水平滚动时,列表也会垂直移动。这使得用户不太友好。我可以在水平滚动时禁用垂直滚动。我正在使用

<com.devsmart.android.ui.HorizontalListView
        android:id="@+id/hlistview"
        android:layout_width="match_parent"
        android:layout_height="155dp"
        android:layout_margin="6dp"
        android:background="#fff"
        android:fitsSystemWindows="true"
    />

用于水平列表视图

2 个答案:

答案 0 :(得分:4)

这个想法是禁用父列表视图来拦截触摸事件。这可能有效:

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

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

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

参考:https://stackoverflow.com/a/22609646/1239966

答案 1 :(得分:0)

最佳方式。

将给定的代码放在你的水平listview onScroll方法上,它可以正常工作

RTSP