问题
I need to scroll 2 parallel HorizontalScrollView dependently, which means that if I'm scrolling one, the other one should scroll too.
How can I do such a thing?
Thanks in advance.
回答1:
hscrollViewOne=(HorizontalScrollView)findViewById(R.id.hsvOne);
hscrollViewTwo=(HorizontalScrollView)findViewById(R.id.hsvTwo);
hscrollViewOne.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
hscrollViewTwo.scrollTo(scrollX, scrollY);
}
});
hscrollViewTwo.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
hscrollViewOne.scrollTo(scrollX,scrollY);
}
});
来源:https://stackoverflow.com/questions/15119329/horizontalscrollviews-scrolling-together