当前位置: 首页 > news >正文

安卓实现微信聊天气泡

一搜没一个能用的,我来:

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="wrap_content"><TextViewandroid:id="@+id/history_time"app:layout_constraintTop_toTopOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"android:text="05月25日 22:14"android:layout_width="wrap_content"android:layout_height="wrap_content"/><com.xmkjsoft.xhgh.self.CircularImageViewandroid:src="@color/main_color"android:id="@+id/head_img"app:layout_constraintTop_toBottomOf="@id/history_time"app:layout_constraintLeft_toLeftOf="parent"android:layout_width="40dp"android:layout_height="40dp"/><!-- 聊天气泡中的内容,如文本、图片等 --><TextViewapp:layout_constraintTop_toTopOf="@id/head_img"app:layout_constraintLeft_toRightOf="@id/head_img"app:layout_constraintRight_toRightOf="parent"android:background="@drawable/left_chat_bubble"android:layout_marginRight="20dp"android:id="@+id/message_text_left"android:layout_width="0dp"android:paddingLeft="20dp"android:paddingTop="5dp"android:paddingBottom="5dp"android:layout_height="wrap_content"android:text="这是一个左这是一个左这是一个左这是一个这是一个左这是一个左这是一个一个这是一个左这是一个左"android:textColor="@color/white"android:textSize="16sp" /><!--右消息--><com.xmkjsoft.xhgh.self.CircularImageViewandroid:layout_marginTop="20dp"android:src="@color/main_color"android:id="@+id/head_img_right"app:layout_constraintTop_toBottomOf="@id/message_text_left"app:layout_constraintRight_toRightOf="parent"android:layout_width="40dp"android:layout_height="40dp"/><!-- 聊天气泡中的内容,如文本、图片等 --><TextViewapp:layout_constraintTop_toTopOf="@id/head_img_right"app:layout_constraintRight_toLeftOf="@id/head_img_right"app:layout_constraintLeft_toLeftOf="parent"android:background="@drawable/right_chat_bubble"android:layout_marginLeft="20dp"android:id="@+id/message_text_right"android:layout_width="0dp"android:paddingRight="10dp"android:paddingLeft="10dp"android:paddingTop="5dp"android:paddingBottom="5dp"android:layout_height="wrap_content"android:text="这是一个左这是一个左这是一个左这是一个这是一个左这是一个左这是一个一个这是一个左这是一个左"android:textColor="@color/white"android:textSize="16sp" /><!--    <TextView-->
<!--        android:background="@drawable/left_chat_bubble"-->
<!--        android:layout_marginLeft="20dp"-->
<!--        android:text="你好6666666666"-->
<!--        -->
<!--        android:layout_width="wrap_content"-->
<!--        android:layout_height="wrap_content"/>--></androidx.constraintlayout.widget.ConstraintLayout>

左边气泡 drawable 文件:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"><item><layer-list><item android:left="8dp"><shape><corners android:radius="4dp" /><solid android:color="@color/main_color" /></shape></item></layer-list></item><itemandroid:gravity="left|top"android:top="10dp"><rotateandroid:fromDegrees="45"android:pivotX="50%"android:pivotY="135%"><shape android:shape="rectangle"><sizeandroid:width="8dp"android:height="8dp" /><solid android:color="@color/main_color" /></shape></rotate></item>
</layer-list>

右边气泡 drawable 文件:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"><item><layer-list><item android:right="8dp"><shape><corners android:radius="4dp" /><solid android:color="#4CAF50" /></shape></item></layer-list></item><itemandroid:gravity="right|top"android:top="0dp"><rotateandroid:fromDegrees="45"android:pivotX="-135%"android:pivotY="50%"><shape android:shape="rectangle"><sizeandroid:width="8dp"android:height="8dp" /><solid android:color="#4CAF50" /></shape></rotate></item>
</layer-list>

相关文章:

  • springboot集成gzip和zip数据压缩传输-满足2k数据自动压缩(适用大数据信息传输)
  • c++将一个复杂的结构体_保存成二进制文件并读取
  • Spark2.0
  • 简单爬虫案例——爬取快手视频
  • BMA530 运动传感器
  • 【LeetCode】976. 三角形的最大周长
  • Kafka 位移
  • rpm包下载
  • 自然语言处理基本知识(1)
  • 【CSS】深入探讨 CSS 的 `calc()` 函数
  • 熊猫烧香是什么?
  • 什么是CC攻击,如何防止网站被CC攻击的方法
  • Spring Cloud LoadBalancer基础入门与应用实践
  • 如何获得更高质量的回答-chatgpt
  • vue为啥监听不了@scroll
  • 【RocksDB】TransactionDB源码分析
  • ABAP的include关键字,Java的import, C的include和C4C ABSL 的import比较
  • CSS中外联样式表代表的含义
  • ES6, React, Redux, Webpack写的一个爬 GitHub 的网页
  • mongo索引构建
  • OpenStack安装流程(juno版)- 添加网络服务(neutron)- controller节点
  • passportjs 源码分析
  • Quartz初级教程
  • Vue组件定义
  • 多线程 start 和 run 方法到底有什么区别?
  • 开源中国专访:Chameleon原理首发,其它跨多端统一框架都是假的?
  • 力扣(LeetCode)22
  • 区块链共识机制优缺点对比都是什么
  • 如何将自己的网站分享到QQ空间,微信,微博等等
  • 一份游戏开发学习路线
  • 国内唯一,阿里云入选全球区块链云服务报告,领先AWS、Google ...
  • ​configparser --- 配置文件解析器​
  • ​LeetCode解法汇总2583. 二叉树中的第 K 大层和
  • ​RecSys 2022 | 面向人岗匹配的双向选择偏好建模
  • #【QT 5 调试软件后,发布相关:软件生成exe文件 + 文件打包】
  • #LLM入门|Prompt#1.8_聊天机器人_Chatbot
  • #我与Java虚拟机的故事#连载15:完整阅读的第一本技术书籍
  • (04)Hive的相关概念——order by 、sort by、distribute by 、cluster by
  • (Matlab)遗传算法优化的BP神经网络实现回归预测
  • (附源码)ssm捐赠救助系统 毕业设计 060945
  • (简单) HDU 2612 Find a way,BFS。
  • (六)什么是Vite——热更新时vite、webpack做了什么
  • (强烈推荐)移动端音视频从零到上手(上)
  • (全部习题答案)研究生英语读写教程基础级教师用书PDF|| 研究生英语读写教程提高级教师用书PDF
  • (状压dp)uva 10817 Headmaster's Headache
  • .gitignore文件—git忽略文件
  • .mat 文件的加载与创建 矩阵变图像? ∈ Matlab 使用笔记
  • .Net 4.0并行库实用性演练
  • .NET Core 项目指定SDK版本
  • .NET Framework Client Profile - a Subset of the .NET Framework Redistribution
  • .NET导入Excel数据
  • .vimrc php,修改home目录下的.vimrc文件,vim配置php高亮显示
  • ::前边啥也没有
  • [Android Pro] listView和GridView的item设置的高度和宽度不起作用
  • [AutoSar]工程中的cpuload陷阱(三)测试