Code Monkey home page Code Monkey logo

stickyheaderscrollview's Introduction

前言

作为ConsecutiveScroller使用者首先感谢作者提供这个库,但是这个控件有个不能继续使用bug,一直未能没修复,

#80 严重影响了用户体验

虽然评论区我提供了CoordinatorLayout+CollapsingToolbarLayout+AppBarLayout$ScrollingViewBehavior+minHeight(吸顶)解决方案。但是依然不够完美,

首先没有作者这个库ConsecutiveScroller能支持多个吸顶布局。

第二也是非常讨厌的问题在AppBarLayout的视图里面上下滑动,滑动过程会停止一下,这个列表滑动的操作不连续,当然这个问题只有在AppBarLayout的视图非常大的时候才会发现。

我还有一个解决方案就是全部用RecyclerView多布局类型来做,然后重写ItemDecoration来实现吸顶功能,但是这种吸顶使用复杂,还存在视图回收在回来需要重新绑定数据的这种问题。

虽然我不想重复造轮子,但是逼不得已。于是下面这个新的库出现了。

简介

StickyHeaderScrollView是Android下支持吸顶Sticky,滚动布局NestedScrollView嵌套RecyclerView,解决CoordinatorLayout、AppBarLayout快速滑动fling停住卡住回弹抖动等bug。

StickyHeaderScrollView支持NestedScrolling机制。

有网友提问scrollview嵌套recyclerview会影响recyclerview 的item复用么
答案是当然不会啊!recyclerview的高度是动态计算的,不是无限高度。

效果图

滚动布局NestedScrollView嵌套RecyclerView
NestedScrollView嵌套ViewPager2
device-2021-06-03-175146.gif

支持SwipeRefreshLayout下拉刷新
动态改变布局不影响吸顶
device-2021-06-03-175146 (1).gif

使用文档

<?xml version="1.0" encoding="utf-8"?>
<com.kongnan.headerscrollview.HeaderScrollView 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"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <com.kongnan.headerscrollview.StickyLinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <!-- 布局省略 -->

            <TextView
                android:id="@+id/remove_view"
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:background="@android:color/background_dark"
                android:text="吸顶View-1"
                android:textColor="@color/purple_200"
                app:isSticky="true" />

           <!-- 布局省略 -->

        </com.kongnan.headerscrollview.StickyLinearLayout>

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>
</com.kongnan.headerscrollview.HeaderScrollView>

就是如此简单,详细使用请看Demo

LICENSE

没有使用协议,两个类HeaderScrollView和StickyLinearLayout拿去随便用。

掘金

欢迎评论区讨论 https://juejin.cn/post/6969759148862865415/

stickyheaderscrollview's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.