RecycleView设置倒置排序,实现聊天列表界面
2017-08-30 10:26
483 查看
一,错误方法
1.聊天数据倒序排列,取出前15条做为第一页数据。
2.将数据再次倒序排列,绑定在Adapter中显示。
3.recycleview 滑动到底部
4.recycleView下拉刷新时,获取第二页数据;同样再次倒序排列,追加到adapter顶部;
5.用上述方法实现逻辑过于繁琐,而且每次进入聊天界面,会有列表滑动到底部的动画,影响用户体验;
二。方法改进
1.recycleView 设置倒序排列
2.聊天数据倒序排列,取出前15条做为第一页数据。
3.将数据绑定在adapter上
4.recycleView下拉,滑动到顶部,继续下拉刷新获取第二页数据;
5.新增发送消息时,将消息追加到消息列表顶端(即展示在recycleView底部)
6.实现效果预览
1.聊天数据倒序排列,取出前15条做为第一页数据。
2.将数据再次倒序排列,绑定在Adapter中显示。
3.recycleview 滑动到底部
recycleView.smoothScrollToPosition(adapter.getItemCount());
4.recycleView下拉刷新时,获取第二页数据;同样再次倒序排列,追加到adapter顶部;
public void appendData(List<BeanChat> chats) { if (listChat.size() == 0) { listChat = chats; } else { List<BeanChat> newList = new ArrayList<BeanChat>(); for (Iterator<BeanChat> it = chats.iterator(); it.hasNext(); ) { newList.add(it.next()); } //新数据追加到顶部 listChat.addAll(0, newList); } notifyDataSetChanged(); }
5.用上述方法实现逻辑过于繁琐,而且每次进入聊天界面,会有列表滑动到底部的动画,影响用户体验;
二。方法改进
1.recycleView 设置倒序排列
LinearLayoutManager layoutManager = (LinearLayoutManager)recycleView.getLayoutManager(); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); layoutManager.setReverseLayout(true);
2.聊天数据倒序排列,取出前15条做为第一页数据。
3.将数据绑定在adapter上
public void appendData(List<BeanChat> chats) { listChat.addAll(chats); notifyDataSetChanged(); }
4.recycleView下拉,滑动到顶部,继续下拉刷新获取第二页数据;
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { if (15 >= localDataCount) { swipeRefreshLayout.setRefreshing(false); return; } getChatList(); //绑定成功下一页数据后,recycleView向上滑动200像素;(简单实现,优化部分后续处理) recycleView.smoothScrollBy(0, -200); swipeRefreshLayout.setRefreshing(false); } });
5.新增发送消息时,将消息追加到消息列表顶端(即展示在recycleView底部)
public void addData(BeanChat chat) { Log.i(TAG, "addData: " + chat.getChatId()); listChat.add(0, chat); notifyItemInserted(0); }
6.实现效果预览
相关文章推荐
- 关于如何通过recycleview实现聊天界面的效果
- recycleview实现分组列表
- 封装使用ViewHolder模式的Adapter组件,及用其快速实现聊天界面
- android模拟聊天界面recyclerview实现
- 封装使用ViewHolder模式的Adapter组件,及用其快速实现聊天界面
- RecycleView设置点击的两种方式:adapter中的onBindViewHolder(VH,int)方法中进行;实现RecyclerView的addonItemTouchListerner()
- <五>RecycleView+CardView实现瀑布流(类in界面效果)
- 使用RecycleView实现动态获取数据展开二级列表展示
- LSettingView--- 让你更加快速的实现设置界面
- UIScrollView 自动排序的功能 (高度/宽度不规则格子) 比如聊天界面—扫荡界面
- 自定义RecycleView实现TV应用上的item焦点获取以及设置当前选中的item居中
- android实现界面左右滑动(GridView动态设置item,支持每个item按某个属性排序来显示在不同的界面)
- 实现RecycleView动态使列表item可以点击或不可点击切换
- 纯代码实现QQ聊天界面---TableView使用详解
- View事件传递(解决聊天界面点击除editText区域以外其他位置实现隐藏软键盘----点击发送按钮不隐藏软键盘)
- 如何在App中实现IM功能之七快速实现聊天列表排序模块——箭扣科技Arrownock
- RecycleView与ItemDecoration实现悬停头部分组列表
- RecyclerView实现聊天界面
- 使用RecyclerView实现聊天界面
- volley+NetworkImageView实现列表界面的列表项中的左侧图标展现之【实现已经加载的列表项的图标上翻的时候不重新加载】