+-
RecyclerView简单的布局管理器 – turn-layout-manager
Turn Layout Manager

A simple carousel for RecyclerView.

Usage

Just create a newTurnLayoutManagerusing the constructor:

TurnLayoutManager(context, // provide a context Gravity.START, // from which direction should the list items orbit? Orientation.VERTICAL, // Is this a vertical or horizontal scroll? radius, // The radius of the item rotation peek, // Extra offset distance shouldRotate); // should list items angle towards the center? true/false.

Just like aLinearLayoutManager, aTurnLayoutManagerspecifies an orientation, eitherVERTICALorHORIZONTALfor vertical and horizontal scrolling respectively.

In addition to orientation, supply aGravity(eitherSTARTorEND). Together, these define the axis of rotation.

Gravity.START Orientation.VERTICAL ┏─────────┓ ┃ x ┃ ┃ x ┃ ┃ x ┃ ┃ x ┃ ┃ x ┃ ┃ x ┃ ┃ x ┃ ┗─────────┛ Gravity.END Orientation.VERTICAL ┏─────────┓ ┃ x ┃ ┃ x ┃ ┃ x ┃ ┃ x ┃ ┃ x ┃ ┃ x ┃ ┃ x ┃ ┗─────────┛ Gravity.START Orientation.HORIZONTAL ┏─────────┓ ┃x x┃ ┃ x x ┃ ┃ xxx ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗─────────┛ Gravity.END Orientation.HORIZONTAL ┏─────────┓ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ xxx ┃ ┃ x x ┃ ┃x x┃ ┗─────────┛ Install

Add the JitPack repository to your root build.gradle

allprojects { repositories { ... maven { url 'https://jitpack.io' } } }

Add the dependency to your module’s build.gradle

dependencies { compile 'com.github.cdflynn:turn-layout-manager:v1.0' } How It Works

TurnLayoutManageruses the base functionality ofLinearLayoutManagerwith some slight modifications. Child views are positioned normally asLinearLayoutManagerdoes, but they’re offset along the rotation radius and peek distance. This involves some trade offs.

Benefits: Automatically supports predictive animations , including mutations to radius and peek distance. Inherits stable support for different scroll directions and therefore can introduce support forGravity. Does not attempt to re-solve the huge variety of edge cases thatLinearLayoutManageralready solves, and thus avoids re-introducing those exceptions. Drawbacks: It’s less efficient than a from-scratch implementation ofLayoutManager. Specifically,TurnLayoutManagerwill have a strictly longer layout pass thanLinearLayoutManager, and for very heavyweight list rows it may drop a frame thatLinearLayoutManagerotherwise would not. No matter what layout manager you use, try to keep your item layouts efficient. List items are not forced to adjust their position parallel to the scroll direction, only their perpendicular offset. Items enter and leave the screen a bit faster than they would on a real turning surface, though the effect is subtle.

A full re-implementation of a newLayoutManagercould potentially solve those drawbacks.

点击查看更多相关文章

转载注明原文:RecyclerView简单的布局管理器 – turn-layout-manager - 乐贴网