安卓应用开发 MyWeChat(二)

本文介绍了安卓应用MyWeChat的第二部分开发过程,包括实现微信Fragment的界面展示,如静态消息列表、点击确认已读、下拉刷新等功能。详细讲述了RecycleView的使用,ChatAdapter的编写,以及界面滑动置顶和删除效果的实现。此外,还提到了消息列表头像图片处理和按钮颜色自定义的方法。
摘要由CSDN通过智能技术生成

往期回顾

安卓应用开发 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获取再绑定数据)


                
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值