ScrollView嵌套ListView listView展示及分页处理
来源:互联网 发布:美化桌面的软件 编辑:程序博客网 时间:2024/05/29 08:09
1.自定义ListView 重写OnMeasure方法适应ScrollView:
public class ListViewForScrollView extends ListView { public ListViewForScrollView(Context context) { super(context); } public ListViewForScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public ListViewForScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } /** * 重写该方法,达到使ListView适应ScrollView的效果 */ @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); }}2:ScrollView滑动到底部ListView分页处理:
2.1:自定义ScrollView重写onOverScrolled方法 :
public class PageListScrollView extends ScrollView { private OnScrollToBottomListener mOnScrollToBottomListener; public PageListScrollView(Context context) { super(context); } public PageListScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public PageListScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } //滚动到底部时,clampedY变为true,此时将回调将状态传出去 @Override protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) { super.onOverScrolled(scrollX, scrollY, clampedX, clampedY); if (scrollY > 0 && mOnScrollToBottomListener != null) { mOnScrollToBottomListener.onScrollBottomListener(clampedY); } } public void setOnScrollToBottomListener(OnScrollToBottomListener listener) { mOnScrollToBottomListener = listener; } public interface OnScrollToBottomListener { void onScrollBottomListener(boolean isBottom); }}
3.在布局文件里嵌套:
<PageListScrollView android:id="@+id/scroll" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:divider="@drawable/divider" android:orientation="vertical" android:showDividers="middle"> <!--其他布局-->
........
<ListViewForScrollView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="wrap_content" /></LinearLayout></com.jingcai.apps.qualitydev.component.widget.PageListScrollView>
3.在activity中监听:
@Overridepublic void onScrollBottomListener(boolean isBottom) { if (isBottom) { //page+1 再次请求}}
阅读全文
0 0
- ScrollView嵌套ListView listView展示及分页处理
- ScrollView嵌套ListView分页加载
- ScrollView嵌套Listview处理方法
- ScrollView嵌套ListView,listview高度问题全展示
- 浅谈ScrollView嵌套ListView及ListView嵌套的高度计算
- ListView嵌套ListView,ScrollView嵌套ListView
- ScrollView嵌套ListView处理事件冲突
- ScrollView或者ListView中嵌套ViewPager,展示不出来问题。
- ScrollView或者ListView中嵌套ViewPager,展示不出来问题。
- android ScrollView嵌套ListView
- ScrollView中嵌套ListView
- ScrollView中嵌套ListView
- ScrollView中嵌套ListView
- ScrollView嵌套 ListView
- android ScrollView嵌套ListView
- ScrollView嵌套ListView解决办法
- ScrollView和ListView嵌套
- ScrollView中嵌套ListView
- c++程序员 常用工具集
- 再谈运放SlewRate-SR
- thymeleaf js函数失效
- laravel5.4控制器构造函数取不到用户信息解决方案
- 實驗六 树和二叉树的实验2
- ScrollView嵌套ListView listView展示及分页处理
- MacBook Pro 下vue项目开发环境搭建,安装和配置apache
- 使用GnuPG(PGP)加密信息及数字签名教程
- UI 设计师不容错过的12款APP UI 交互设计
- Android 音频播放之SoundPool类的使用
- leetcode28 Implement strStr()
- 11月6日云栖精选夜读:阿里云双11访谈之云安全
- Mac安装Python支持包
- 每日一练20171106