安卓应用开发 MyWeChat(二)
往期回顾
项目gitee仓库
相应项目gitee地址 免费的虎粮shong yi shong 免费的星星点一点
weixinFragment初步界面效果展示
要实现的初步界面效果如下所示:
实现weixinFragment初步界面(RecycleView)
首先实现消息列表与确认已读功能,根据想要完成的效果将整个界面分为三步:静态消息列表、点击确认已读、下拉刷新(由于是静态数据,仅有刷新动效)。
在完成layout_chat_item和fragment_weixin两个xml后需要重写RecycleView.Adapter的ChatAdapter类以及编写weixinFragment的静态数据。
静态消息列表
要实现静态的消息列表,需要先完成单一消息的布局(需要对单一消息设计功能,所以需要区分相应的消息,显然不可能编写总体列表),即layout_chat_item.xml。在winxinFragment中通过获取编写的item显示出消息列表,以下为layout_chat_item.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_chat_item1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/layout_chat_item_imageView"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:scaleType="centerCrop"
tools:srcCompat="@drawable/chat_item_pic0" />
<LinearLayout
android:id="@+id/layout_chat_item2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/layout_chat_item3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/layout_chat_item_textView1"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="TextView1"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="@+id/layout_chat_item_textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:gravity="center_horizontal"
android:text="TextView3"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="@+id/layout_chat_item_textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="TextView2"
android:textSize="16sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="20dp"
android:background="@color/black" />
</LinearLayout>
</LinearLayout>
以下为fragment_weixin.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".weixinFragment">
<!-- TODO: Update blank fragment layout -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/fragment_chat_recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
在ChatAdapter中完成静态数据的获取方法(holder获取再绑定数据)