如何在Android中自动向上滚动Recycler视图? [英] How to auto scroll up Recycler view in Android?

查看:118
本文介绍了如何在Android中自动向上滚动Recycler视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一些聊天应用程序,可以在其中发送和接收消息.但是问题是,无论何时我发送或接收消息,回收者视图都不会滚动到顶部,因此消息会在键盘上方显示.

I have developed some chat application where i can send and received messages. But the problem is whenever i send or receive messages the recycler view is not scrolling to top so that messages gets diplayed above the keypad.

我已经使用了上面提到的回收站视图android.support.v7.widget.RecyclerView.

I have used the above mentioned recycler view android.support.v7.widget.RecyclerView.

推荐答案

在更新recyclerview时,尝试运行以下代码:

On updating recyclerview try to run this code :

recyclerView.post(new Runnable() {
    @Override
    public void run() {
        // Call smooth scroll  
        recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1);                                 
    }
});

这篇关于如何在Android中自动向上滚动Recycler视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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