TabLayout+RecycleView 实现滑动锚点定位

本文介绍了如何使用TabLayout+RecyclerView在Android应用中实现滑动锚点定位的效果,类似于淘宝商品详情页。详细讲解了xml布局、activity编码、适配器的设置,包括控件初始化、布局管理器、锚点联动方法以及适配器的各个关键方法。
摘要由CSDN通过智能技术生成

前言

在我们打开淘宝App,查看某个商品详情的时候,我们就会发现如下图所显示的画面。
没错,这就是我们要介绍的效果,也就是TabLayout+RecycleView 实现的滑动锚点定位。
由于是项目急需,所以细节问题不是很精致。之后有时间会对细节问题进行更改。

效果图

在这里插入图片描述

操作如下

1. xml样式布局

  • imgflash:此 ImageView 图片控件是我设置的返回键
  • imgpush:此ImageView 图片控件是设置的分享键
  • ancharTab:此TabLayout 控件,这里是设置分类效果
  • ancharRecy:此RecycleView 控件,这里是设置滑动多布局
<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#fff"
    tools:context=".taobao.AnchorActivity">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/imgflash"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:background="@drawable/ic_arrow_back_black_24dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/imgpush"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            android:background="@drawable/ic_grain_black_24dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <android.support.design.widget.TabLayout
            android:id="@+id/ancharTab"
            android:layout_width
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值