前言
在我们打开淘宝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