在android中如何判断scrollview的滚动条已经滚动到底部了呢,下面是具体的判断代码
if(getScrollY() + getHeight() >= computeVerticalScrollRange())
{
Log.d(TAG,"------滚动到最下方------");
}
else
{
Log.d(TAG,"没有到最下方");
}
在实际应用中,可以继承ScrollView,来实现这个功能,如下:
public class XScrollView extends ScrollView {\r\n \r\n \r\n protected Context ctx=null;\r\n public XScrollView(Context context) {\r\n super(context);\r\n ctx=context;\r\n \r\n // TODO Auto-generated constructor stub\r\n }\r\n protected OnScrollStateChanged sc=null;\r\n public void setOnScrollStateChanged(OnScrollStateChanged _sc)\r\n {\r\n sc=_sc;\r\n }\r\n @Override\r\n protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX,\r\n boolean clampedY) {\r\n // TODO Auto-generated method stub\r\n if(getScrollY() + getHeight() >= computeVerticalScrollRange())\r\n {\r\n sc.ScrollBottom();\r\n }\r\n super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);\r\n }\r\n}
public interface OnScrollStateChanged\r\n{\r\n public void ScrollTop();\r\n public void ScrollBottom();\r\n}