1.首先效果是这样的:
2.开始动手
1.我认为做一个界面肯定是先考虑布局对吧,一个聊天界面肯定是有一行行的聊天信息,我们不难想到可以用到recyclerview或者listview来展现这一功能,而现在官方更推荐我们使用前者,因为前者功能更加强大,而且实现更加方便,但使用之前这个控件是属于新增控件,我们需要在support库里面导入这一控件文件,而据我们所知,无论是recyclerview还是listview它都有一个适配器,适配器里面有一个函数是用来专门设置子布局的(即一行行的内容),不难看出,子布局可以设置为2个以某张图片作为背景图的textview,而背景要怎样设置呢,这里有一个小技巧,我们可以在用一个linearlayout来镶嵌textview,再设置它的src属性,这样不就行了吗,然后下面就是一个Edittext和button.
子布局:
?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="wrap_content"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/left"
android:layout_gravity="left"
android:background="@drawable/message_left"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/left_msg"
android:layout_margin="10dp"
android:layout_gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_c