安卓实现微信聊天气泡

embedded/2024/9/25 8:21:03/

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

布局文件:

<?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.ppmy.cn/embedded/55900.html

相关文章

NPM 常用命令

NPM 常用命令 NPM&#xff08;Node Package Manager&#xff09;是 JavaScript 生态系统中最流行的包管理工具&#xff0c;它不仅可以管理 Node.js 项目的依赖&#xff0c;还提供了丰富的命令来管理和发布你的代码。本文将从不同角度&#xff0c;深入浅出地介绍 NPM 的常用命令…

【力扣 - 每日一题】3115. 质数的最大距离(一次遍历、头尾遍历、空间换时间、埃式筛、欧拉筛、打表)Golang实现

原题链接 题目描述 给你一个整数数组 nums。 返回两个&#xff08;不一定不同的&#xff09;质数在 nums 中 下标 的 最大距离。 示例 1&#xff1a; 输入&#xff1a; nums [4,2,9,5,3] 输出&#xff1a; 3 解释&#xff1a; nums[1]、nums[3] 和 nums[4] 是质数。因此答…

配置WLAN 示例

规格 仅AR129CVW、AR129CGVW-L、AR109W、AR109GW-L、AR161W、AR161EW、AR161FGW-L、AR161FW、AR169FVW、AR169JFVW-4B4S、AR169JFVW-2S、AR169EGW-L、AR169EW、AR169FGW-L、AR169W-P-M9、AR1220EVW和AR301W支持WLAN-FAT AP功能。 组网需求 如图1所示&#xff0c;企业使用WLAN…

Rust Eq 和 PartialEq

Eq 和 PartialEq 在 Rust 中&#xff0c;想要重载操作符&#xff0c;你就需要实现对应的特征。 例如 <、<、> 和 > 需要实现 PartialOrd 特征: use std::fmt::Display;struct Pair<T> {x: T,y: T, }impl<T> Pair<T> {fn new(x: T, y: T) ->…

Open AI Stream Completion Set Variable Inside Function PHP With Openai-php SDK

题意&#xff1a;使用 OpenAI 的 PHP SDK&#xff08;例如 openai-php&#xff09;来在函数内部设置和完成一个流&#xff08;stream&#xff09;相关的变量 问题背景&#xff1a; How to set variable inside this openai-php sdk function in stream completion ? I am usi…

自动编码器简单理解及简单使用描述

1. 什么是自动编码器&#xff1f; 自动编码器分为编码器和解码器&#xff0c;其中解码器只在训练阶段用到。具体过程就是&#xff1a; 首先&#xff0c;输入训练样本&#xff0c;编码器对输入样本进行编码&#xff0c;对其进行降维&#xff0c;直到到达某个瓶颈层&#xff1b…

工具提示框(Tooltip): 设计、应用与最佳实践

工具提示框&#xff08;Tooltip&#xff09;: 设计、应用与最佳实践 引言 工具提示框&#xff08;Tooltip&#xff09;是用户界面&#xff08;UI&#xff09;设计中的一种常见元素&#xff0c;它为用户提供关于界面元素或操作的额外信息。当用户将鼠标悬停在某个元素上时&…

你了解人工智能吗?

前言 人工智能&#xff08;Artificial Intelligence&#xff0c;AI&#xff09;是计算机科学的一个重要分支&#xff0c;致力于开发能够执行通常需要人类智能的任务的系统。本文将从历史发展、关键技术、应用领域以及未来挑战等方面&#xff0c;深入探讨人工智能的相关内容。 …