展会信息港展会大全

android scrollview 动态滚动
来源:互联网   发布日期:2015-10-03 10:51:09   浏览:1096次  

导读:android scrollview 动态滚动protected void onScrollChanged(int x, int y, int oldx, int oldy)Unfortunately Google never thought that we would need to access it, which is why ......

android scrollview 动态滚动

protected void onScrollChanged(int x, int y, int oldx, int oldy)

Unfortunately Google never thought that we would need to access it, which is why they made it protected and didn't add a "setOnScrollChangedListener" hook. So we will have to do that for ourselves.

First we need an interface.

package com.test;

public interface ScrollViewListener {

void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy);

}

package com.test;

import android.content.Context;

import android.util.AttributeSet;

import android.widget.ScrollView;

public class ObservableScrollView extends ScrollView {

private ScrollViewListener scrollViewListener = null;

public ObservableScrollView(Context context) {

super(context);

}

public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);

}

public ObservableScrollView(Context context, AttributeSet attrs) {

super(context, attrs);

}

public void setScrollViewListener(ScrollViewListener scrollViewListener) {

this.scrollViewListener = scrollViewListener;

}

@Override

protected void onScrollChanged(int x, int y, int oldx, int oldy) {

super.onScrollChanged(x, y, oldx, oldy);

if(scrollViewListener != null) {

scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);

}

}

赞助本站

人工智能实验室

相关热词: scrollview 滚动

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港