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

Yaw*_*war 2 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"
    />
Run Code Online (Sandbox Code Playgroud)

用于水平列表视图

Shi*_*rma 5

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

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;
            }
        });
Run Code Online (Sandbox Code Playgroud)

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