禁用垂直滚动,当用户在Android的横向滚动 [英] Disable vertical scroll when user scrolling horizontally in android

查看:249
本文介绍了禁用垂直滚动,当用户在Android的横向滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个垂直的自定义列表和垂直列表中的每个项目包含水平列表视图。当我再横向滚动列表也小垂直移动。这使得它不太人性化。我可以禁用垂直滚动,而水平滚动。我使用

I have a vertical custom list and each item of vertical list contains a horizontal list-view. When I scroll horizontally then list also moves little vertically. Which makes it less user friendly. Can I disable vertical scrolling while scrolling horizontally. I am using

<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"
    />

水平列表视图

推荐答案

我们的想法是禁用列表视图父拦截触摸事件。这可能工作:

The idea is to disable the parent listview to intercept touch event. This might work :

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;
            }
        });

参考:<一href=\"http://stackoverflow.com/a/22609646/1239966\">http://stackoverflow.com/a/22609646/1239966

这篇关于禁用垂直滚动,当用户在Android的横向滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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