记录一下关键点

布局最关键

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"tools:context=".index.detail.blank.MessageActivity"><LinearLayoutandroid:id="@+id/root"android:clipChildren="false"android:clipToPadding="false"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><Viewandroid:id="@+id/statusbar"android:layout_width="match_parent"android:layout_height="@dimen/dp10"android:background="@color/skyblue" /><TextViewandroid:id="@+id/tvTitle"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@color/skyblue"android:gravity="center"android:paddingTop="@dimen/dp10"android:paddingBottom="@dimen/dp10"android:text="二狗子"android:textColor="@color/black"android:textSize="20sp" /><!--    android:background="#F9F5F5"--><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:orientation="vertical"><ImageViewandroid:id="@+id/ivBg"android:layout_width="match_parent"android:layout_height="match_parent"android:scaleType="fitXY"android:src="@drawable/messagebg" /><FrameLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_above="@id/llBot"android:layout_weight="1"android:orientation="vertical"><com.scwang.smart.refresh.layout.SmartRefreshLayoutandroid:id="@+id/smartrefresh"android:layout_width="match_parent"android:layout_height="wrap_content"><com.scwang.smart.refresh.header.ClassicsHeaderandroid:layout_width="match_parent"android:layout_height="wrap_content"/><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/rv"android:layout_width="match_parent"android:layout_height="wrap_content" /></com.scwang.smart.refresh.layout.SmartRefreshLayout></FrameLayout><LinearLayoutandroid:id="@+id/llBot"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:background="#D3D1D1"android:orientation="horizontal"><ImageViewandroid:layout_width="@dimen/dp40"android:layout_height="@dimen/dp40"android:layout_gravity="bottom"android:padding="@dimen/dp8"android:src="@mipmap/ic_launcher" /><FrameLayoutandroid:id="@+id/etFrame"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_marginTop="@dimen/dp4"android:layout_marginBottom="@dimen/dp4"android:layout_weight="1"><EditTextandroid:id="@+id/etInput"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:layout_marginLeft="@dimen/dp4"android:layout_marginTop="@dimen/dp4"android:layout_marginRight="@dimen/dp4"android:layout_marginBottom="@dimen/dp4"android:background="@null"android:clickable="true"android:focusable="true"android:maxHeight="@dimen/dp100"android:textColor="@color/black"android:textSize="18sp" /></FrameLayout><ImageViewandroid:layout_width="@dimen/dp40"android:layout_height="@dimen/dp40"android:layout_gravity="bottom"android:padding="@dimen/dp8"android:src="@mipmap/ic_launcher" /><FrameLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="bottom"><ImageViewandroid:id="@+id/ivSetting"android:layout_width="@dimen/dp40"android:layout_height="@dimen/dp40"android:padding="@dimen/dp8"android:src="@mipmap/ic_launcher" /><TextViewandroid:id="@+id/tvSend"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_marginRight="@dimen/dp8"android:background="#4CAF50"android:paddingLeft="@dimen/dp10"android:paddingTop="@dimen/dp4"android:paddingRight="@dimen/dp10"android:paddingBottom="@dimen/dp4"android:text="发送"android:textSize="16sp"android:visibility="gone" /></FrameLayout></LinearLayout></RelativeLayout></LinearLayout></layout>

关键点2.底部输入框的高度

获取到底部总高度

  //获取控件的试图观察者,以便通过试图观察者得到控件的宽高参数val viewTreeObserver: ViewTreeObserver = bind!!.llBot.getViewTreeObserver()//添加观察者监听viewTreeObserver.addOnGlobalLayoutListener(object :ViewTreeObserver.OnGlobalLayoutListener {override fun onGlobalLayout() {//回调监听后首先移除该监听 占资源bind!!.tvTitle.getViewTreeObserver().removeOnGlobalLayoutListener(this)//得到高度llBotheight = bind!!.llBot.getHeight()}})
  bind!!.etInput.addTextChangedListener(object : TextWatcher {override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}override fun afterTextChanged(s: Editable?) {val toString = s.toString()val trim = toString.trim()if (!TextUtils.isEmpty(trim)) {bind!!.tvSend.visibility = View.VISIBLE} else {bind!!.tvSend.visibility = View.GONE}val layoutParams = bind!!.llBot.layoutParams as RelativeLayout.LayoutParamslayoutParams.bottomMargin = layoutParams.height + keyboardHeightbind!!.rv.scrollToPosition(mutableListOf.size - 1)val ivBglayoutParams = bind!!.ivBg.layoutParams as RelativeLayout.LayoutParamsivBglayoutParams.bottomMargin = bind!!.llBot.height - llBotheightif (keyboardHeight == 0) {val ivBglayoutParams = bind!!.ivBg.layoutParams as RelativeLayout.LayoutParamsivBglayoutParams.bottomMargin = 0}}})bind!!.tvSend.setOnClickListener {var toString = bind!!.etInput.text.toString()if (TextUtils.isEmpty(toString)) {return@setOnClickListener}var subInt = 0for (i in toString.length - 1 downTo 0) {if (TextUtils.equals("\n".toString(), toString.get(i).toString())) {subInt = i} else {break}}if (subInt != 0) {toString = toString.subSequence(0, subInt) as String;}mutableListOf.add(SessTypebean(SessTypebean.TYPE1, SessionBean(toString)))sessionAdapter.notifyItemRemoved(mutableListOf.size - 1)bind!!.rv.scrollToPosition(mutableListOf.size - 1)// 重置bind!!.etInput.setText("")}
  override fun onResume() {super.onResume()KeyboardUtils.registerSoftInputChangedListener(window,object : KeyboardUtils.OnSoftInputChangedListener {override fun onSoftInputChanged(height: Int) {keyboardHeight = heightval layoutParams = bind!!.llBot.layoutParams as RelativeLayout.LayoutParamslayoutParams.bottomMargin = heightbind!!.rv.scrollToPosition(mutableListOf.size - 1)if (height == 0) {val ivBglayoutParams = bind!!.ivBg.layoutParams as RelativeLayout.LayoutParamsivBglayoutParams.bottomMargin = 0}}})}override fun onPause() {super.onPause()KeyboardUtils.unregisterSoftInputChangedListener(window)val layoutParams = bind!!.llBot.layoutParams as RelativeLayout.LayoutParamslayoutParams.bottomMargin = 0}

Android 微信聊天页面相关推荐

  1. android高仿微信聊天页面,Android 高仿微信语音聊天页面高斯模糊(毛玻璃效果)

    目前的应用市场上,使用毛玻璃效果的APP随处可见,比如用过微信语音聊天的人可以发现,语音聊天页面就使用了高斯模糊效果. 先看下效果图: 仔细观察上图,我们可以发现,背景图以用户头像为模板,对其进行了高 ...

  2. html怎么实现聊天界面设计,纯css制作仿微信聊天页面

    纯css制作仿微信聊天页面 *{ margin: 0; padding: 0; } body{ font-size: 14px; } .triangle{ margin: 100px auto ; w ...

  3. netty案例,netty4.1中级拓展篇五《基于Netty搭建WebSocket,模仿微信聊天页面》

    前言介绍 本章节我们模仿微信聊天页面,开发一个基于Netty搭建WebSocket通信案例.Netty的应用方面非常广:聊天.MQ.RPC.数据等等,在5G到来的时候更加需要大量数据传输,Netty的 ...

  4. android如何实现批量删除操作,Android 基于聊天页面如何实现批量转发和批量删除...

    Android 基于聊天页面如何实现批量转发和批量删除继承 ConversationFragment 类,重写 showMoreClickItem 并返回 true . 重写 getMoreClick ...

  5. PyQt模拟微信聊天页面开发

    一.引述 网上关于Qt模拟微信.QQ的页面开发的多如牛毛,但C++本身来说逻辑上难上手,对只会Python的小伙伴来说太痛苦了. 今天就为大家开个场(下节更精彩),众所周知,要想模拟微信.QQ等这种聊 ...

  6. 小程序(十六)小程序仿微信聊天页面及功能

    后期打算在小程序中添加即时聊天的功能,但是目前这个还没有考虑好以一种什么样的形势去实现,先接入一个腾讯AI提供的免费闲聊接口.先做一个大概的页面及功能. 腾讯AI地址: https://ai.qq.c ...

  7. Android微信登录页面实现

    利用Android实现微信手机端的登录页面,对于登录的输入做了一些的条件限制诸如,非空,长度限制等: 效果图如下: xml文件代码: <?xml version="1.0" ...

  8. python+flask实现和人工智能机器人对话(仿微信聊天页面)| 【Python系列】

    情人节已经过了但是情人节和我们程序员有什么关系,没对象自己new一个不就完了. 话不多说直接上成品. 实现机器人的方式很多,可以深度学习训练机器人使其能与我们进行交流,但是请记住,所拥有的数据越多,机 ...

  9. android微信运动页面开发,微信小程序仿微信运动步数排行(交互)

    微信小程序仿微信运动步数排行(交互) 发布时间:2020-08-20 00:51:02 来源:脚本之家 阅读:101 作者:祈澈姑娘 本文介绍了微信小程序仿微信运动步数排行(交互),分享给大家,也给自 ...

  10. iOS仿微信聊天页面长按气泡弹窗

    显示效果图如上,

最新文章

  1. 【100题】第十五题(树的镜像问题)
  2. 250鲁大师跑分_我装了一台鲁大师 230W 分的神机,3A 游戏平台装机作业
  3. bootstrap table移动端_bootstrap介绍
  4. Apache用户认证、默认虚拟主机、域名301跳转
  5. shiro将session认证改成token认证_初步学习Shiro框架 第一集
  6. C语言程序所以,C语言程序(1)
  7. Java中NLP的学习
  8. 传智播客java学习之面向对象(抽象类) , 接口
  9. 注册csdn博客步骤
  10. java 读取文件内容 方法
  11. Java学习里程-----Java基础_26 BigDecimal类
  12. 成为指弹更好的吉他手必做的10件事
  13. Python小白自问自答
  14. 腾讯Android开发面试记录,附大厂真题面经
  15. 简单之美——系统设计黄金法则
  16. 机器学习模型中的损失函数loss function
  17. Learning to Rank基于pairwise的算法(一)——Ranking SVM、MHR、IRSVM
  18. 你也可以看懂,量子力学的困惑,测不准原理 薛定谔的猫 !
  19. 数据结构-KMP手算next与nextval(全网最简单,包会)
  20. 机器学习经典书籍和论文集合

热门文章

  1. python #hsv空间中Hue色度/色调在色相环上的角#冷暖色调 在色相环上的范围
  2. EV:ePWM+eCAP
  3. intel服务器芯片组历史,Intel单路服务器芯片组披露
  4. 我是80后程序员,我支持正版!
  5. 13、【算法】算法复杂度分析
  6. 【可视化入门】智慧物流服务中心——可视化实例(动态)
  7. latex公式图片识别(转换为latex语法格式)
  8. GitHub 官宣:弃用 trending 热榜,开发者炸锅了
  9. Excel巧做项目管理
  10. 罗振宇2021跨年演讲5:为什么你要建成自己的“黄鹤楼”?