如何检测自定义滚动视图的结束?
How to detect the end of the custom scroll view?
我已经完成了垂直滚动 view.what 我的要求是,我只需要检测滚动视图的结束并制作按钮 visible.Can 谁能告诉我如何检测滚动视图已到达底部?
public class LockableVerScroll extends ScrollView {
private boolean isScrollable;
private ScrollListener scrollListener=null;
public LockableVerScroll(Context context)
{
super(context);
isScrollable=true;
}
public LockableVerScroll(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
isScrollable=true;
}
public LockableVerScroll(Context context, AttributeSet attrs,int defStyle)
{
super(context, attrs, defStyle);
isScrollable=true;
}
public boolean isScrollable()
{
return isScrollable;
}
public boolean setScrollable(boolean mScrollable)
{
return mScrollable=isScrollable;
}
public void setScrollViewListener(ScrollListener mscrollListener)
{
this.scrollListener=mscrollListener;
}
需要帮助..提前致谢!
覆盖 ScrollView
扩展中的 onScrollChanged()
方法
@Override
protected void onScrollChanged(int l1, int t1, int l2, int t2) {
int count = getChildCount();
View view = (View) getChildAt(count - 1);
int delta = (view.getBottom() - (getHeight() + getScrollY() + view.getTop()));
if( delta == 0 )
{
// scrollview has reached bottom, do whatever you want here.
}
super.onScrollChanged(l1, t1, l2, t1);
}
试试这个。这会起作用。
编辑:
if( delta == 0 )
{
// define interface in Activity / Fragment and call its method here
mScrollListener.onScrollViewHitsBottom();
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
View view = (View) getChildAt(getChildCount()-1);
int diff = (view.getBottom()-(getHeight()+getScrollY()+view.getTop()));// Calculate the scrolldiff
if( diff == 0 ){ // if diff is zero, then the bottom has been reached
Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached" );
}
super.onScrollChanged(l, t, oldl, oldt);
}
我已经完成了垂直滚动 view.what 我的要求是,我只需要检测滚动视图的结束并制作按钮 visible.Can 谁能告诉我如何检测滚动视图已到达底部?
public class LockableVerScroll extends ScrollView {
private boolean isScrollable;
private ScrollListener scrollListener=null;
public LockableVerScroll(Context context)
{
super(context);
isScrollable=true;
}
public LockableVerScroll(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
isScrollable=true;
}
public LockableVerScroll(Context context, AttributeSet attrs,int defStyle)
{
super(context, attrs, defStyle);
isScrollable=true;
}
public boolean isScrollable()
{
return isScrollable;
}
public boolean setScrollable(boolean mScrollable)
{
return mScrollable=isScrollable;
}
public void setScrollViewListener(ScrollListener mscrollListener)
{
this.scrollListener=mscrollListener;
}
需要帮助..提前致谢!
覆盖 ScrollView
onScrollChanged()
方法
@Override
protected void onScrollChanged(int l1, int t1, int l2, int t2) {
int count = getChildCount();
View view = (View) getChildAt(count - 1);
int delta = (view.getBottom() - (getHeight() + getScrollY() + view.getTop()));
if( delta == 0 )
{
// scrollview has reached bottom, do whatever you want here.
}
super.onScrollChanged(l1, t1, l2, t1);
}
试试这个。这会起作用。
编辑:
if( delta == 0 )
{
// define interface in Activity / Fragment and call its method here
mScrollListener.onScrollViewHitsBottom();
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
View view = (View) getChildAt(getChildCount()-1);
int diff = (view.getBottom()-(getHeight()+getScrollY()+view.getTop()));// Calculate the scrolldiff
if( diff == 0 ){ // if diff is zero, then the bottom has been reached
Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached" );
}
super.onScrollChanged(l, t, oldl, oldt);
}