获取在滚动视图滚动方向? [英] Get scrolling direction in a scrollview?

查看:93
本文介绍了获取在滚动视图滚动方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是pretty的简单,但我好像错过了什么---你怎么找出方向(左/右/上/下)的滚动型滚动事件?

This should be pretty straightforward but it seems that I missed something --- how do you figure out the direction (left/right/up/down) of a scrolling event for a ScrollView?

,想到的第一件事是存储getScrollX()和getScrollY(),然后到onTouchListener下次调用进行比较。那是做事的正确方法?

The first thing that comes to mind is to store getScrollX() and getScrollY(), then compare them in the next call to the onTouchListener. Is that the right way of doing things?

我实现自定义Horizo​​ntalScrollView,我需要禁用滚动和页面挥笔只在一个方向。

I'm implementing a custom HorizontalScrollView and I need to disable scrolling and page swipes in one direction only.

推荐答案

研究告诉我,有没有滚动监听的情况下。照片 你可以试试你的approch。
另一件事我会尝试是覆盖<一个href="http://developer.android.com/reference/android/view/View.html#onScrollChanged%28int,%20int,%20int,%20int%29">onScrollChanged (这之前提供滚动位置)等创建自己的滚动型

Research is telling me that there is no scroll listener for that case.
You could try your approch.
Another thing I would try is to override onScrollChanged (which provides the scroll position before) and so creating your own ScrollView

更新
这一次workes我。它滚动到的权利,但不能向左侧。

Update:
This one workes for me. It scrolls to the right but not to the left.

public class CustomScrollView extends HorizontalScrollView {

    public CustomScrollView(Context context) {
        super(context);
    }

    public CustomScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public void onScrollChanged(int w, int h, int ow, int oh) {
        if (w < ow) {
            scrollTo(ow, h);
        }
    }
}

这篇关于获取在滚动视图滚动方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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