HorizontalScrollViews scrolling together

2019-08-14 04:17发布

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条回答
老娘就宠你
2楼-- · 2019-08-14 04:42
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);
        }
    });
查看更多
登录 后发表回答