关于ListView,GridView,ScrollView是否滑动到了顶部或者底部处理
2016-05-16 09:54
417 查看
我也是在研究下拉刷新,上拉加载时必须要判断的,首先ListView和GridView一样,通过判断fisrtPosition是否为0(ListView.getCcount)和firstView距离顶部或者底部的距离来判断,具体代码:
private boolean isTop(ListView listView){
View firstView=null;
if(listView.getCount()==0){
return true;
}
firstView=listView.getChildAt(0);
if(firstView!=null){
if(listView.getFirstVisiblePosition()==0&&firstView.getTop()==listView.getListPaddingTop()){
return true;
}
}else{
return true;
}
return false;
}
至于ScrollView的判断则是另一种,具体代码:
private boolean isBottom(ScrollView scrollView){
if(scrollView.getScrollY()==0){
return true;
}
return false;
}
private boolean isTop(ListView listView){
View firstView=null;
if(listView.getCount()==0){
return true;
}
firstView=listView.getChildAt(0);
if(firstView!=null){
if(listView.getFirstVisiblePosition()==0&&firstView.getTop()==listView.getListPaddingTop()){
return true;
}
}else{
return true;
}
return false;
}
private boolean isBottom(ListView listView){ int lastPosition=listView.getLastVisiblePosition(); int count=listView.getCount(); int childCount=listView.getChildCount(); View lastVisibaleView=listView.getChildAt(childCount-1); if(childCount==count){ return true; } if(lastVisibaleView!=null){ if(lastPosition==count-1&&lastVisibaleView.getBottom()+listView.getListPaddingBottom()==listView.getHeight()){ return true; } } return false; }
至于ScrollView的判断则是另一种,具体代码:
private boolean isBottom(ScrollView scrollView){
if(scrollView.getScrollY()==0){
return true;
}
return false;
}
private boolean isBottom(ScrollView sc){ int scrollY=sc.getScrollY(); int height=sc.getHeight(); View view=sc.getChildAt(0); if(view==null){ return true; }else{ if((scrollY+height)>=view.getMeasuredHeight()){//滑到了底部 return true; } } return false; }
相关文章推荐
- python字符类型的一些方法
- 【第十章】集成其它Web框架 之 10.3 集成Struts2.x ——跟我学spring3
- 聊聊 KVC 和 KVO 的高阶应用
- 数据分析一般过程
- iOS 代码实现自定义TableView 自定义TableViewCell
- theano学习指南4(翻译)- 卷积神经网络
- Spring MVC 注解事务 之 异常回滚
- iOS中比较两个数组是否一样
- 开源代码网站
- 应用架构(转)
- php curl请求转发
- Java 中日期的几种常见操作 —— 取值、转换、加减、比较
- Activity主题设置问题 You need to use a Theme.AppCompat theme (or descendant) with this activity.
- (Android架构)T-MVP:泛型深度解耦下的MVP大瘦身
- httpd无法启动
- 关于继承RecyclerView.Adapter报错
- Oracle基于时间点的恢复
- Redis开启远程登录连接。
- P2P 行业解决方案
- TableView的优化