Android-反向列表视图作为消息显示 [英] Android - Reverse listview as message display

查看:72
本文介绍了Android-反向列表视图作为消息显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对我的Android应用有一个小疑问. 我搜索了很长时间,但对我的问题一无所获.

I've got a little question for my Android App. I searched for a long time but found nothing about my problem.

场景:我必须显示一个还原列表视图(作为Facebook Messenger). 当用户滚动到顶部时,加载更多消息.

Scenario : I've to display a revert listview (as Facebook Messenger). And when the user scrolls to the top, load more messages.

问题:notifiyDataAsChanged()调用后,滚动不一样! 我想保留与加载前完全相同的位置.

Problem : After notifiyDataAsChanged() call, the scroll is not the same! I want to conserve exactly the same position as before loading.

我尝试了该代码:

// save index and top position
int index = list.getFirstVisiblePosition()+result.size();
View v = list.getChildAt(index);
int top = (v == null) ? 0 : v.getTop();

// ...
// restore
list.setSelectionFromTop(index, top);

但是在加载后,滚动不完全相同.

你有个主意吗?

推荐答案

我认为您应该使用 StackFromBottom 与您的列表视图:

I think you should look into using TranscriptMode and StackFromBottom with your listview:

android:stackFromBottom="true"
android:transcriptMode="normal"

通过将成绩单模式设置为正常,只有在最后一个项目已经在视图中时,它才会滚动到底部.这样,您的用户可以在调用notifydatasetchanged时不中断地查看以前的列表视图项.

By setting the transcript mode to normal it will scroll to the bottom only if the last item was already in view. That way your users can view the previous list view items without interruption when you call notifydatasetchanged.

这篇关于Android-反向列表视图作为消息显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆