同步两个水平滚动视图的android [英] synchronize two horizontal scroll view android
问题描述
我有两个水平滚动查看每个都包含在它的线性布局项目。怎么可能同步滚动,当任它滚动,另一个也会自动滚动。任何帮助吗?
i have two horizontal scroll views each containing a linear layout item under it. how is it possible to synchronize the scroll, when either of it is scrolled, the other is also automatically scrolled. any help?
推荐答案
你可以做的是在第一个水平滚动视图的onTouch,记录它开始与下一个动作的X位置。然后,当你有移动的动作,记录在X位置的变化。然后,您可以拨打第二个水平滚动视图的scrollBy(DELTAX,0)。在最多的一个动作或取消,一定要重新设置您的状态变量。
What you could do is on the onTouch of the first Horizontal Scroll view, record the X position that it started with for an action of Down. Then when you have an action of Move, record the change in the X position. Then you can call the second horizontal scroll view's scrollBy (deltaX, 0). On an action of Up or Cancel, make sure to reset your state variables.
我有一个列表视图滚动垂直滚动只使用Y位置,而不是十,这是我的code做到这一点做到了这一点。该concurrentScroller是我的俯视图。
I've done this with a List View scrolling a vertical scroll, just using Y positions instead of X. Here is my code to accomplish this. The concurrentScroller is my vertical view.
if(concurrentScroller != null) {
int deltaY = (int) (startTouchConcurrentY - ev.getY());
startTouchConcurrentY = ev.getY();
concurrentScroller.scrollBy(0, deltaY);
}
这篇关于同步两个水平滚动视图的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!