cdflynn / turn-layout-manager
- суббота, 15 июля 2017 г. в 03:13:21
A carousel layout manager for RecyclerView
A simple carousel for RecyclerView.
Just create a new TurnLayoutManager
using 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 a LinearLayoutManager
, a TurnLayoutManager
specifies an orientation, either VERTICAL
or HORIZONTAL
for vertical and horizontal scrolling respectively.
In addition to orientation, supply a Gravity
(either START
or END
). 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┃
┗─────────┛
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'
}
TurnLayoutManager
uses the base functionality of LinearLayoutManager
with some slight modifications. Child views are positioned normally as LinearLayoutManager
does, but they're offset along the rotation radius and peek distance. This involves some trade offs.
Gravity
.LinearLayoutManager
already solves, and thus avoids re-introducing those exceptions.LayoutManager
. Specifically, TurnLayoutManager
will have a strictly longer layout pass than LinearLayoutManager
, and for very heavyweight list rows it may drop a frame that LinearLayoutManager
otherwise would not. No matter what layout manager you use, try to keep your item layouts efficient.A full re-implementation of a new LayoutManager
could potentially solve those drawbacks.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.