Android实现淘宝、京东首页浏览效果

这篇博客展示了如何在Android中实现类似淘宝、京东首页的浏览效果,包括SwipeRefreshLayout全局刷新,ViewPager嵌套Fragment的上拉加载,以及滑动到顶部时tab悬浮吸顶。在实现过程中,博主总结了三个难点:ViewPager缓存清理,TabLayout与ViewPager集成后的Tab显示问题,以及Fragment懒加载的实现。提供了一个完整的demo供读者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果图实例如下:

效果图实例

内容如下:
1.SwipeRefreshLayout刷新全局数据、更新ViewPager内的数据
2.ViewPager嵌套Fragment实现RecyclerView数据的上拉加载
3.滑动到顶部、tab悬浮吸顶

下面是主要布局的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipe_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:addStatesFromChildren="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="118dp"
                android:background="#FFEF2A52"
                android:orientation="vertical">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="38dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:layout_marginLeft="15dp"
                        android:text="艺术品鉴"
                        android:textColor="#ffffffff"
                        android:textSize="18sp" />

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_marginRight="15dp"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <ImageView
                            android:id="@+id/saoma_btn"
                            android:layout_width="20dp"
                            android:layout_height="20dp"
                            android:src="@drawable/shouye_ereima" />

                        <ImageView
                            android:id="@+id/leiji_btn"
                            android
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值