简单的仿QQ聊天(自娱自乐聊天室)

本文介绍如何设计和实现一个简单的仿QQ聊天界面。主要包括聊天界面布局的搭建,使用ListView显示聊天信息,以及表情发送和消息发送的功能实现。通过创建布局文件、Adapter和消息类,实现了聊天界面的交互效果。
摘要由CSDN通过智能技术生成

设计思路:

首先搭建聊天界面,想要的效果如下

这里写图片描述

整体为linearlayout线性布局 :
1.顶部是聊天界面的名称 一个TextView
2.中间是ListView 用来显示聊天信息
3.底部是一个水平布局的linearlayout,包含表情 发送按钮 输入框EditText

然后搭建聊天信息的布局

此处的布局效果如下
这里写图片描述
1.整体为水平布局的linearlayout,分为ImageView和右边的linearlayout
2.右边又是一个竖直的linearlayout,分为上面的linearlayout(包括两个TextView)和下面的TextView.

代码实现

两个布局文件

1、聊天界面布局,layout下的chat.xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/chat_background"//整体的背景
    android:orientation="vertical">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/green"
        android:gravity="center"字体位于中间
        android:text="自娱自乐聊天室"
        android:textSize="20sp" />
    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"//自由充满,防止list下面的内容被挤出去
        android:background="@drawable/chat_background"
        android:cacheColorHint="#00000000"//设置屏幕滑动的颜色为透明
        android:divider="@null"></ListView>//设置每条消息之间没有横线隔开
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/hui"
        android:gravity="center">

        <ImageView
            android:id="@+id/chat_image"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:src="@mipmap/addsimle" />//添加表情的按钮图标

        <Button
            android:id="@+id/button_back"
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:background="@drawable/btn_background"
            android:text="回复" />

        <EditText
            android:id="@+id/chat_edittext"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/denglu"
            android:hint="输入内容" />

        <Button
            android:id="@+id/button_send"
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:background="@drawable/btn_background"
            android:text="发送" />
    </LinearLayout>
</LinearLayout>
————————————————————————————————————————————————————
//这里面android:background="@drawable/chat_background"整体背景的设置使用渐变色 在@drawable/chat_background下的代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
     //由上到下颜色渐变
        android:startColor="#ace7ef"
        android:centerColor="#c5e1dd"
        android:endColor="#e7d9c5"
        android:type="linear" //线性渐变 此外还有radial圆形渐变,sweep扇形渐变
        android:angle="-90"/>
</shape>

完成后布局如下:
这里写图片描述

2、消息布局,layout下的message.xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<TextView
    android:id="@+id/message_time"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="星期几 时间"//在每条消息上方显示该消息发送的日期和时间
    android:gravity="center"
    android:padding="10dp"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView//头像,插入图片 设置大小
            android:id="@+id/message_img"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:src="@mipmap/t1"/>
        <LinearLayout//竖直分布的LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="5dp">
            <LinearLayout//水平布局的LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:
一、源码描述 GG2014是QQ的高仿版,包括客户端和服务端,可在广域网部署使用。我的目标并不 是做一个QQ仿版的玩具,而是希望做成一个能够真正使用的产品(这个过程还有 很长的路要走),并持续维护下去。小编亲自测试完美运行,强烈推荐一下,感兴趣 的朋友们千万不要错过啊。 二、功能介绍 GG2014 已经实现了如下功能: (01)注册、登录、添加好友、好友列表。 (02)自拍头像。 (03)文字聊天、字体设置、GIF动态表情、窗口震动、截图、手写板、登录状态 (在线、离开、忙碌、勿打扰、隐身)、输入提醒 (04)群功能:创建群、加入群、退出群、群聊天 (05)文件传送、文件夹传送(支持断点续传) (06)语音视频聊天 (07)远程磁盘 (08)远程协助 (09)共享桌面(可以指定要共享的桌面区域) (10)可靠的P2P (11)网盘 (12)离线消息 (13)离线文件 (14)语音消息、语音留言 (15)最近联系人列表 (16)系统设置:开机自动启动、麦克风设备索引、摄像头设备索引,叉掉主窗口时 关闭程序还是隐藏窗口。 (17)聊天记录:支持本地保存和服务器端保存两种方式。 (18)好友分组:新增/删除分组,修改分组名称,改变好友的所属分组。 (19)托盘闪动:跟QQ完全一样,当接收到消息时,托盘会闪动对应好友的头像。点 击头像,将弹出与好友的聊天框。 (20)输入提醒:像QQ一样,当对方正在输入消息时,我这边的聊天框可以看到对方 “正在输入”的提示。 (21)自动记录:GG2014会自动记录上次打开的主界面的位置、大小;最后一次打开 的聊天窗口的大小;最后一次 设定的字体的颜色、大小等。 (22)打开聊天窗口时,自动显示上次交谈的最后一句话。 三、注意事项 1、开发环境为Visual Studio 2010,无数据库,使用.net 2.0开发。 2、该源码仅供学习交流使用。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值