当前位置: 首页 > 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>

http://www.lryc.cn/news/389223.html

相关文章:

  • 软件测试(功能、接口、性能、自动化)详解 | 测试人生路
  • 【面试题】网络IO模型
  • 数据结构-----【链表:基础】
  • 如何在pycharm里面运行pytest用例
  • Charles抓包工具踩坑记录
  • 【RabbitMQ实战】邮件发送(直连交换机、手动ack)
  • python 笔试面试八股(自用版~)
  • 《SpringBoot+Vue》Chapter04 SpringBoot整合Web开发
  • 腾讯地图异步调用
  • 通过docker overlay2 目录名查找占用磁盘空间最大的容器名和容器ID
  • 每周算法:有向图强连通分量
  • Python习题 053:在逻辑值检测时会被认为是真值的是?
  • 基于RackNerd + CentOS 7 64 Bit + aaPanel 的那些事
  • 大数据期末复习——hadoop、hive等基础知识
  • 什么是客户体验自动化?
  • 高效除氟:探索CH-87up树脂在氟化工废水处理中的应用
  • 【Git】LFS
  • 隐式转换的魔法:Scala中隐式转换的深度解析
  • 外贸企业选择什么网络?
  • Redis 7.x 系列【14】数据类型之流(Stream)
  • (四)opengl函数加载和错误处理
  • RuoYi-Vue3不启动后端服务如何登陆?
  • Typora(跨平台 Markdown 编辑器 )正版值得购买吗
  • springboot个人证书管理系统-计算机毕业设计源码16679
  • 读-改-写操作
  • 海外仓系统应用教程:解决了小型海外仓哪些问题
  • shell 脚本编程
  • gin参数验证
  • 【web3】分享一个web入门学习平台-HackQuest
  • Sectigo或RapidSSL DV通配符SSL证书哪个性价比更高?