Android开发——RecycleView之编写精美的聊天界面的练习 (十五)

操作流程:

1.准备好收发消息的背景图片

(上一篇有提到相关制作步骤)
在这里插入图片描述

2.在build.grade中添加依赖库

因为用到RecycleView
在这里插入图片描述
记得
在这里插入图片描述

3.编写主页面 activity_main.xml

在主页面中放置一个RecycleView用于显示聊天内容,放置一个EditText用于输入消息,Button用于send,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/background">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/msg_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
       <EditText
           android:id="@+id/input_text"
           android:layout_width="0dp"
           android:layout_weight="1"
           android:hint="Type something here"
           android:layout_height="wrap_content"
           android:maxLines="2"/>
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Send"
            android:textAllCaps="false"/>

    </LinearLayout>
</LinearLayout>

在这里插入图片描述

4.新建Msg

这个类中有两个字段,content表示消息的内容,type表示消息的类型(接收/发送)
相关代码如下:

public class Msg {
   
    public static final int TYPE_RECEIVED = 0;
    public static final int TYPE_SENT = 1;
    private String conent;
    private int type;

    public Msg(String content, int type) {
   
        this.conent = content;
        this
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值