Home

Awesome

Turn Layout Manager

A simple carousel for RecyclerView.

Demo

Usage

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┃
┗─────────┛

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 {
    implementation 'com.github.cdflynn:turn-layout-manager:v1.3.1'
}

How It Works

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.

Benefits:
Drawbacks:

A full re-implementation of a new LayoutManager could potentially solve those drawbacks.

License

   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.