如何判断ScrollView是否滚动
1个回答
推荐于2016-07-12 · 知道合伙人数码行家
可以叫我表哥
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:25897
获赞数:1464989
2010年毕业于北京化工大学北方学院计算机科学与技术专业毕业,学士学位,工程电子技术行业4年从业经验。
向TA提问 私信TA
关注
展开全部
有的。但这是个protected方法,只能被其自身或者子类调用。你可以继承ScrollView,重载该方法,然后就可以在这个方法里面判断是否发生了滚动了。我曾经有类似需要,采取一种方式是自己定义一个listener,然后在方法里面去调用listener。但重载的是onOverScrolled,你可以参考如下代码自己改写一下即可:[mw_shl_code=java,true]
public class CustomScrollView extends ScrollView {
private OnOverScrolledListener mOnOverScrolledListener = null;
/**
* @param context
*/
public CustomScrollView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
/**
* @param context
* @param attrs
*/
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
/**
* @param context
* @param attrs
* @param defStyle
*/
public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see android.widget.ScrollView#arrowScroll(int)
*/
@Override
public boolean arrowScroll(int arg0) {
// TODO Auto-generated method stub
return super.arrowScroll(arg0);
}
/* (non-Javadoc)
* @see android.widget.ScrollView#computeScroll()
*/
@Override
public void computeScroll() {
// TODO Auto-generated method stub
super.computeScroll();
}
/**
* @return the mOnOverScrolledListener
*/
public OnOverScrolledListener getOnOverScrolledListener() {
return mOnOverScrolledListener;
}
/**
* @param mOnOverScrolledListener the mOnOverScrolledListener to set
*/
public void setOnOverScrolledListener(OnOverScrolledListener mOnOverScrolledListener) {
this.mOnOverScrolledListener = mOnOverScrolledListener;
}
public interface OnOverScrolledListener{
public abstract void onOverScrolled(View view, int scrollX, int scrollY, boolean clampedX, boolean clampedY);
}
/* (non-Javadoc)
* @see android.widget.ScrollView#onOverScrolled(int, int, boolean, boolean)
*/
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
// TODO Auto-generated method stub
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
if(mOnOverScrolledListener != null) {
mOnOverScrolledListener.onOverScrolled(this, scrollX, scrollY, clampedX, clampedY);
}
Log.i("CustomScrollView", "===DBG:onOverScrolled");
}
}
[/mw_shl_code]
public class CustomScrollView extends ScrollView {
private OnOverScrolledListener mOnOverScrolledListener = null;
/**
* @param context
*/
public CustomScrollView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
/**
* @param context
* @param attrs
*/
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
/**
* @param context
* @param attrs
* @param defStyle
*/
public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see android.widget.ScrollView#arrowScroll(int)
*/
@Override
public boolean arrowScroll(int arg0) {
// TODO Auto-generated method stub
return super.arrowScroll(arg0);
}
/* (non-Javadoc)
* @see android.widget.ScrollView#computeScroll()
*/
@Override
public void computeScroll() {
// TODO Auto-generated method stub
super.computeScroll();
}
/**
* @return the mOnOverScrolledListener
*/
public OnOverScrolledListener getOnOverScrolledListener() {
return mOnOverScrolledListener;
}
/**
* @param mOnOverScrolledListener the mOnOverScrolledListener to set
*/
public void setOnOverScrolledListener(OnOverScrolledListener mOnOverScrolledListener) {
this.mOnOverScrolledListener = mOnOverScrolledListener;
}
public interface OnOverScrolledListener{
public abstract void onOverScrolled(View view, int scrollX, int scrollY, boolean clampedX, boolean clampedY);
}
/* (non-Javadoc)
* @see android.widget.ScrollView#onOverScrolled(int, int, boolean, boolean)
*/
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
// TODO Auto-generated method stub
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
if(mOnOverScrolledListener != null) {
mOnOverScrolledListener.onOverScrolled(this, scrollX, scrollY, clampedX, clampedY);
}
Log.i("CustomScrollView", "===DBG:onOverScrolled");
}
}
[/mw_shl_code]
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询