Skip to content

nicochofly/CustomLayoutManager

 
 

Repository files navigation

Custom-Layout-Manager

Building your own LayoutManager faster.

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

Usage

Gradle

compile 'rouchuan.customlayoutmanager:customlayoutmanager:1.0.1'

####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.isClockWise determine the way how each items align

//Default pass isClockWise true
public CustomLayoutManager(Context context){
    this(context,true);
}

public CustomLayoutManager(Context context, boolean isClockWise) {
    this.context = context;
    this.isClockWise = isClockWise;
}

####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;
}

####Enable springback

recyclerView.addOnScrollListener(new CenterScrollListener());

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.

About

A Circle and a zoom layoutManager for android RecyclerView

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%