码迷,mamicode.com
首页 > 其他好文 > 详细

【实战】聊天窗口的实现

时间:2016-03-06 23:30:26      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:

  今天参考书上的例子,自己也实现了一个相对美观的聊天界面,过程如下:

一、第一步制作用于显示聊天内容的图片,使用SDK目录下的Tools下的draw9patch.bat来制作Nine-Patch图片,以便适用于各种分辨率的终端;

  需要注意的是在制作好之后保存的时候不能把保存的名称改掉,一定要带上保存时自动加上的.9,并且在引用的时候名称不用写.9即可,切记!在这浪费了一个多小时

二、编写主界面activity_main.xml,放一个ListView和LinearLayout,LinearLayout下面再放一个EditText(用于编写消息)和Button(用于发送消息)

技术分享
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:id="@+id/LinearLayout1"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:orientation="vertical"
 7     android:background="#d8e0e8" >
 8 
 9     <ListView
10         android:id="@+id/msg_list_view"
11         android:layout_width="match_parent"
12         android:layout_height="0dp"
13         android:layout_weight="1"
14         android:divider="#0000" >
15     </ListView>
16     
17     
18     <LinearLayout 
19         android:layout_width="match_parent"
20         android:layout_height="wrap_content">
21         <EditText android:id="@+id/input_text"
22             android:layout_width="0dp"
23             android:layout_height="wrap_content"
24             android:layout_weight="1"
25             android:hint="Type something here"
26             android:maxLines="2"/>
27         
28         <Button 
29             android:id="@+id/send"
30             android:layout_width="wrap_content"
31             android:layout_height="wrap_content"
32             android:text="Send"/>
33         
34     </LinearLayout>
35 </LinearLayout>
activity_main.xml

三、新建消息实体类Msg

技术分享
 1 package com.example.Entity;
 2 
 3 public class Msg {
 4     public static final int TYPE_RECEIVED = 0;
 5     public static final int TYPE_SEND = 1;
 6     private String content;//消息内容
 7     private int type;//消息类型,分为发送(TYPE_SEND)和接收的(TYPE_RECEIVED)
 8     
 9     public Msg(String content, int type) {
10         // TODO Auto-generated constructor stub
11         this.content = content;
12         this.type = type;
13     }
14 
15     public String getContent() {
16         return content;
17     }
18 
19     public int getType() {
20         return type;
21     }
22 
23 }
Msg

 

【实战】聊天窗口的实现

标签:

原文地址:http://www.cnblogs.com/csschn/p/5248976.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!