首页 > 移动平台 > 详细

Android Studio 之 编写精美的聊天界面

时间:2021-01-31 17:35:05      阅读:245      评论:0      收藏:0      [点我收藏+]

 

 

?准备工作

  首先制作一张 .9 格式的聊天气泡,参见我的这篇博客

  新建一个 Empty Activity,Java 和 XML 文件的命名分别为 MainActivity.java 和 activity_main.xml;

?编写精美的聊天界面

  首先编写主界面,修改 activity_main.xml 中的代码,如下所示:

<?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:padding="10dp"
    android:background="#d8e0e8">

    <androidx.recyclerview.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"
        android:layout_marginTop="5dp"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/input_text"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="Type message here"
            android:textAllCaps="false"
            android:maxLines="2"
            android:gravity="left"/>

        <Button
            android:id="@+id/send"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Send"
            android:textAllCaps="false"
            android:textSize="20sp"/>
    </LinearLayout>

</LinearLayout>

  我们在主界面中放置了一个 RecyclerView 用于显示聊天的消息内容;

  又放置了一个 EditText 用于输入消息,还放置了一个 Button 用于发送消息;

  然后,定义消息的实体类,新建 Msg.java,代码如下:

 

 

Android Studio 之 编写精美的聊天界面

原文:https://www.cnblogs.com/hyacinthLJP/p/14352840.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!