参考网址:https://blog.csdn.net/waterseason/article/details/84021963
https://www.iteye.com/blog/gundumw100-1162554
package com.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.HorizontalScrollView;
public class SyncHorizontalScrollView extends HorizontalScrollView {
private View mView;
public SyncHorizontalScrollView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public SyncHorizontalScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mView != null) {
mView.scrollTo(l, t);
}
}
public void setScrollView(View view) {
mView = view;
}
}
使用方法:
scrollView0=(SyncHorizontalScrollView)findViewById(R.id.scrollView0);
scrollView1=(SyncHorizontalScrollView)findViewById(R.id.scrollView1);
scrollView0.setScrollView(scrollView1);
scrollView1.setScrollView(scrollView0);
如果使用两个HorizontalScrollView联动滑动,美观起见隐藏掉一个的滑动条:android:scrollbars="none"
设置滚动条:https://blog.csdn.net/codywangziham01/article/details/7677342
延伸:
重写ScrollView实现两个ScrollView的同步滚动显示
http://www.cnblogs.com/devinzhang/archive/2012/07/13/2590222.html