Android框架之路——聊天Demo实现

本文介绍了一款Android聊天Demo的实现过程,采用GreenDao存储聊天数据,利用RecyclerView展示聊天界面,结合ButterKnife绑定视图。详细阐述了从数据存储、界面布局到业务逻辑的实现步骤,并提供了Demo下载链接。
摘要由CSDN通过智能技术生成

一、所用技术

  • GreenDao存储聊天数据;
  • RecyclerView根据viewtype显示聊天界面;
  • butterknife绑定view;

   如果这些你还没有了解,你可以参考这些文章:

二、实现效果

后台每5s发送数据过来,存储到数据库中,并显示到界面上,用户可以发送文字,保存到数据库并显示。.9的图片比较丑,缺一个美工姑娘,欢迎联系。。。

三、总体思路

通过RecyclerView的viewType来决定加载左右聊天布局,通过greendao来操作数据库。一些细节问题较多,需要逐个解决。

  1. 编写activity_main.xml,主要由一个RecyclerView和下方的EditText输入框以及发送按钮组成。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:padding="5dp"
        tools:context="com.ping.chatdemo.activity.MainActivity">
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_chatList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/linearLayout">
    
        </android.support.v7.widget.RecyclerView>
    
        <LinearLayout
            android:layout_alignParentBottom="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/linearLayout">
            <android.support.design.widget.TextInputLayout
                android:layout_width="0dp"
                android:layout_weight="6"
                android:layout_height="50dp">
                <EditText
                    android:id="@+id/et_content"
                    android:hint="请输入文字..."
                    android:textSize="15dp"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"/>
            </android.support.design.widget.TextInputLayout>
    
            <Button
                android:id="@+id/bt_send"
                android:padding="10dp"
                android:textSize="15dp"
                android:text="发送"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        </LinearLayout>
    
    </RelativeLayout>
    
  2. 看一下我们的

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值