听滚动事件horizontalscrollview机器人 [英] listening to scroll events horizontalscrollview android
问题描述
我想听取事件时, HorizontalScrollView
滚动。试过,但它并没有打印任何东西。
I am trying to listen to the event when the HorizontalScrollView
is scrolled. Tried this but it does not print anything.
HorizontalScrollView headerScrollView = new HorizontalScrollView(this);
headerScrollView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Log.i("hv1",event.toString());
Log.i("hv1","HELLO");
return false;
}
});
实际的问题是,我想滚动两个 HorizontalScrollView
在time..ie;他们都需要同时滚动时,用于至少一个他们的滚动。
什么解决办法?
The actual problem is, I want to scroll two HorizontalScrollView
at a time..ie; both of them need to scroll simultaneously when atleast one of them scrolled.
any workaround?
我用下面的答案,然后试图实现这一点,但我不知道我是如何使用的方法的类。
I used the answer below and then tried implementing this but I am not sure how I need to use the methods in the class.
TestHorizontalScrollView headerScrollView = (TestHorizontalScrollView) findViewById(R.id.headerHv);
这是我需要指向在布局文件中的HSV元素的方式吗?
Is this the way I need to point to the hsv element in the layout file?
推荐答案
您可以尝试创建一个扩展HorizontalScrollView自己的自定义类并覆盖onScrollChanged()函数,例如
You may want to try creating your own custom class that extends HorizontalScrollView and overriding the onScrollChanged() function as such
public class TestHorizontalScrollView extends HorizontalScrollView {
public TestHorizontalScrollView(Context context) {
super(context);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
// TODO Auto-generated method stub
Log.i("Scrolling", "X from ["+oldl+"] to ["+l+"]");
super.onScrollChanged(l, t, oldl, oldt);
}
}
这被覆盖的功能将捕获所有的变化,即使视图没有被触摸滚动位置。这应该让您的滚动视图同步。
This overriden function will catch all changes to the scroll position even when the view is not being touched. This should keep your scroll views in sync.
这篇关于听滚动事件horizontalscrollview机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!