Coder Social home page Coder Social logo

stickyviewpager's Introduction

这是一个带有“粘性”功能的viewpager。

ViewPager带有粘性功能,常规的处理方法可能会超级复杂,因为涉及到大量的onTouch监听、拦截,滑动时因为效率问题影响用户体验,不信你去看一下应用宝、豌豆荚的App详情页,然后滑动一下试试。

但是这个demo却使用了很讨巧的方法,里面很少看到onTouch拦截、事件消费的逻辑处理。细看代码你会发现,这个demo使用了障眼法,很巧妙的障眼法。这个障眼法的灵感,来源于另外一款App的处理逻辑,我在滑动时不小心琢磨到了。我没有去反编译,没有去看代码,却猜到了大体的框架,这真是一件很有意思的事情。

viewpager左右滑动的时候,始终有一个view“粘”在顶部。Viewpager左边fragment是scrollView,右边是listview。左右两个fragment上下滑动的时候,都会计算并动态调整stickyView的位置。在viewpager左右滑动的时候,两个fragment的stickyView高度之间的契合也做了调整。在豌豆荚和应用宝的app详情页界面,对stickyView的处理太过生硬,用户体验不太友好。可以参考这个demo的实现方案。

先上两张图如下:

viewpager在上下滑动的时候,对stickyview位置的改变,会存在惯性。大多bug已经修复完成,滑动比较流畅。欢迎拍砖~

备注:
该project使用的水平listview是:https://github.com/MeetMe/Android-HorizontalListView --(只修改了dispatchTouchEvent方法)
viewpager指示器是:https://github.com/astuetz/PagerSlidingTabStrip

stickyviewpager's People

Contributors

xmusistone avatar

Watchers

 avatar

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.