检查 scrollview 是否正在滚动 android

Check whether the scrollview is scrolling in android

有一个包含线性布局和一组文本视图的滚动视图。

然后我设置了一个定时器 运行 每 0.1 秒,如果 scrollview 不是 ontouch ,那么 运行 一些函数

下面是我创建定时器的方法

handler = new Handler();

r = new Runnable() {
    @Override
    public void run() {
        s.post(new Runnable() {
            @Override
            public void run() {

                //run some function if not on touch;

                handler.postDelayed(r, 100);
            }
        });
    }
};

handler.postDelayed(r, 100);

问题是如何判断此时scrollview是否ontouch,有setOnTouchListener,但是能不能在特定时间判断ontouch?

感谢您的帮助

您可以将触摸时的滚动视图保存在布尔变量中,在 onTouch 中更新其值并跟踪标志以执行您喜欢的操作。

like say -
//global declaration
Public Boolean scrollviewFlag=false;

//inside onCreate activity

Below is the code to check the touch event of scrollView.

 ScrollView scroll = (ScrollView) findViewById(R.id.scrollView);

    scroll.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP && tochedView != null) {
                Log.i("Touche", "ScrollView ACTION_UP"); 
                srollviewFlag=true;               
                return true;
            }
            srollviewFlag=false;     
            return false;
        }
    });