Git Product home page Git Product logo

dynamicheightviewpager's Introduction

996.icu

blog 地址: https://www.jianshu.com/p/14389b125390

先看效果图

高度随内容平滑改变

可以看到ViewPager随内容的高度平滑改变。

###实现原理

要实现ViewPager的高度随ItemView而变化,那么在滚动前需要获取到itemView的原始高度。

然后监听ViewPager的滚动过程,获取将要展示的下一个ItemView的高度,根据横向滚动比例,实时计算高度。

具体实现可以参考类DynamicHeightViewPagercreatePageTransformer方法

###使用方式

使用方式非常简单,只需要以下几步:

  1. ViewPager使用DynamicHeightViewPager类来代替,改类相对ViewPager 来说只增加了初始化方法init(dynamicHeightItemViews: List<DynamicHeightViewPagerItemInterface>, selectedItem: Int = 0)

  2. ViewPager的每个ItemView需要实现ComplicatedDynamicHeightViewPagerItem接口,改接口中的getOriginContentHeight方法需要返回ItemView的原始高度,根据此高度才能动态计算ViewPager的高度。ItemView需要继承FrameLayout

  3. 调用ViewPager的初始化方法init(dynamicHeightItemViews: List<DynamicHeightViewPagerItemInterface>, selectedItem: Int = 0)

具体使用方法可以参考文末的demo。

#####viewPager中每个Item不会局限于图片,可以是其他UI组件。 当每个Item的子View需要根据ViewPager高度的变化进行缩放时,可以响应ComplicatedDynamicHeightViewPagerItemonScaleChanged(scale: Float)方法。

github地址:https://github.com/HowardChenhaoyang/DynamicHeightViewPager

dynamicheightviewpager's People

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.