聊天页面弹出键盘信息滚动到最后一条
来源:互联网 发布:cadence软件介绍 编辑:程序博客网 时间:2024/05/18 03:37
效果图:
实现原理:
· 给聊天信息展示RecyclerView的根布局添加addOnLayoutChangeListener()监听
代码实现:
1、xml文件里的信息展示布局如下:(代码仅为页面布局的信息展示部分)
<FrameLayout android:id="@+id/fl_chat" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toTopOf="@+id/ll_input" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> <android.support.v7.widget.RecyclerView android:id="@+id/rv_chat" android:layout_width="match_parent" android:layout_height="wrap_content" /> </FrameLayout>
2、在java代码里边的监听设置
//这里flChat为聊天信息展示RecyclerView所在的根布局 FrameLayout flChat = (FrameLayout) findViewById(R.id.fl_chat); flChat.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if (bottom < oldBottom) { //通过RecyclerView的滚动方法将聊天信息滚动到最后一条 rvChat.scrollToPosition(adapterChat.getModels().size() - 1); } } });
3、如果要做到如QQ聊天翻动到中间的时候点击输入框输入内容不滚动最底部,可以给RecyclerView添加addOnScrollListener()监听,判断用户主动滚动查看中间信息部分的话,增加一个boolean值判断,在上部分(2)当中的onLayoutChange()方法判断里增加该boolean值条件。
That’s all, 日常项目当中碰到的小知识点,记录下希望可以帮助到大家。Thank you!
阅读全文
0 0
- 聊天页面弹出键盘信息滚动到最后一条
- 软键盘弹出,listview上移并滚动到最后一条的解决办法
- CListCtrl---滚动到最后一条记录
- 聊天框自动滚动到最后一行
- ListView自动滚动到数据集的最后一条
- 老婆最后一条信息
- 老婆的最后一条信息
- 即时聊天应在viewDidAppear发送scrollToRowAtIndexPath:atScrollPosition:animated滚动到最新一条记录
- 聊天页面由于键盘弹出来,导致自定义的标题栏不见和背景图片都变形了
- SWT带垂直滚动条的Text自动滚动到底部(比如显示聊天信息)
- android 输入法键盘弹出与否判断和输入法键盘弹出时将界面滚动到指定位置
- 软键盘弹出,listview上移并滚动到最后的解决方法
- 软键盘弹出,listview上移并滚动到最后的解决方法
- 软键盘弹出,listview上移并滚动到最后的解决方法 .
- 软键盘弹出,listview上移并滚动到最后的解决方法
- js弹出提示信息,然后跳转到另一页面
- RecyclerView直播聊天界面判断最后一条消息位置
- web网页input框设置,点击input框弹出键盘,再收回键盘,焦点框会随页面滚动
- 27读书笔记之使用HTTP协议访问网络
- php有关api接口的一些原理(验证)
- Python IndentationError 问题
- Logistic回归原理及公式推导
- JavaScript变量 基础篇
- 聊天页面弹出键盘信息滚动到最后一条
- 区块链主流开源技术体系介绍
- 在jQuery 和 HTML5 上轻松使用EasyUI
- curl模拟数据请求,在header头中设置自定义的参数
- Python 多线程
- 万绿丛中一点红 (PAT-1068)
- 宿舍管理查询系统
- Vue2
- 腾讯2017秋招笔试编程题之素数