Giter Club home page Giter Club logo

viewpagerlayoutmanager's Introduction

ViewPager-Layout-Manager

Download

English | δΈ­ζ–‡

A view pager like layout manager with custom ability.

It will handle the recycling under the hood. All you need to concern about is which the property you want to change and how it change accroding to the scroll offset.

Example Example Example Example ExampleExample

Usage

Gradle

RecyclerView is required so:

compile 'com.android.support:recyclerview-v7:[your version code]'

if you want custom your own layout manager please add code below:

compile 'rouchuan.viewpagerlayoutmanager:viewpagerlayoutmanager-core:1.3.1'

or if you want use the effect above please import(No need to import core):

compile 'rouchuan.viewpagerlayoutmanager:viewpagerlayoutmanager-support:1.3.1'

Attention!!!

Make sure that your item view has the same width and height

Enable springback

recyclerView.addOnScrollListener(new CenterScrollListener());

OnPageChangeListener

Only wrok when enabling springback or you need to implement your own OnScrollListene.

mLayoutManager.setOnPageChangeListener(new ViewPagerLayoutManager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

Enable scrollbars

same as recyclerView

 <android.support.v7.widget.RecyclerView
        android:scrollbars="horizontal"
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

Endless Scroll

viewPagerLayoutManager.setEnableEndlessScroll(true);

Customize

Default Properties

protected Context context;

// Size of each items
protected int mDecoratedChildWidth;
protected int mDecoratedChildHeight;

protected int startLeft; //position x of first item
protected int startTop; // position y of first item
protected float offset; //The delta of property which will change when scroll

protected float interval; //the interval between each items

Consturct

By default there are two constructs.mShouldReverseLayout determine the way how each items align

//Default pass mShouldReverseLayout true
public CustomLayoutManager(){
    this(true);
}

public CustomLayoutManager(boolean mShouldReverseLayout) {
    this.mShouldReverseLayout = mShouldReverseLayout;
}

Methods must be implemented.

It will set the interval of each items. Once it was set you can use the variable interval directly

protected abstract float setInterval();

You can set up your own properties or change the default properties like startLeft and startTop here

protected abstract void setUp();

You can set item's properties which is determined by target offset here

protected abstract void setItemViewProperty(View itemView,float targetOffset);

Methods you can override.

The max offset value of which the view should be removed

protected float maxRemoveOffset(){
    return getHorizontalSpace() - startLeft;
}

The min offset value of which the view should be removed

protected abstract minRemoveOffset(){
    return -mDecoratedChildWidth-getPaddingLeft() - startLeft;
}

You can calculate and set the postion x of each items here

protected int calItemLeftPosition(float targetOffset){
    return targetOffset;
}

You can calculate and set the postion y of each items here

protected int calItemTopPosition(float targetOffset){
    return 0;
}

Return the property which you want to change while scrolling

protected float propertyChangeWhenScroll(View itemView){
    return itemView.getLeft()-startLeft;
}

It return the (scroll dx / offset);

protected float getDistanceRatio(){
   return 1f;
}

Change Logs

1.1.0

  1. Spliting single library into core and support
  2. Fixing jumping back to first item when loading image with universal-image-loader
  3. Supporting using scrollToPosition before view inflated
  4. Optimizing performance

1.2.0

  1. Supporting endless scroll
  2. Fixing scrollbar does not show when shouldReverseLayout is true
  3. Fixing scrollToPosition scrolls to wrong position when shouldReverseLayout is true

1.3.0

  1. Fixing crash which caused by wrong position calculation when enabling endless scroll
  2. Add ElevateScaleLayoutManager

1.3.1

  1. Fixing onPageSelected does not trigger when scrolling back distance equals zero
  2. Add RotateLayoutManager

Things to do

  1. support infinite scroll
  2. optimize performance
  3. support indicator
  4. support item view with different size
  5. support other effects (long term subject)

License

Copyright 2016 shenruochuan
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.

viewpagerlayoutmanager's People

Contributors

leochuan avatar qinxiandiqi 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.