带有监听器的滚动视图,api < 23
在您的代码中写下
MyHorizontalScrollView scrollView = (MyHorizontalScrollView)view.findViewById(R.id.scrollViewBrowse);
scrollView.setOnScrollChangedListener(new MyHorizontalScrollView.OnScrollChangedListener() {
@Override
public void onScrollChanged(int l, int t, int oldl, int oldt) {
}
});
我的水平滚动视图
public class MyHorizontalScrollView extends ScrollView {
public OnScrollChangedListener mOnScrollChangedListener;
public MyHorizontalScrollView(Context context) {
super(context);
}
public MyHorizontalScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mOnScrollChangedListener != null) {
mOnScrollChangedListener.onScrollChanged(l, t, oldl, oldt);
}
}
public void setOnScrollChangedListener(OnScrollChangedListener onScrollChangedListener){
this.mOnScrollChangedListener = onScrollChangedListener;
}
public interface OnScrollChangedListener{
void onScrollChanged(int l, int t, int oldl, int oldt);
}
}
* Xml 文件 *
<MyHorizontalScrollView
android:id="@+id/scrollViewBrowse"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@drawable/backgroung"
android:padding="10dp">
</MyHorizontalScrollView>