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.
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'
recyclerView.addOnScrollListener(new CenterScrollListener());
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) {
}
});
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" />
viewPagerLayoutManager.setEnableEndlessScroll(true);
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
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;
}
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);
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;
}
- Spliting single library into core and support
- Fixing jumping back to first item when loading image with universal-image-loader
- Supporting using scrollToPosition before view inflated
- Optimizing performance
- Supporting endless scroll
- Fixing scrollbar does not show when shouldReverseLayout is true
- Fixing scrollToPosition scrolls to wrong position when shouldReverseLayout is true
- Fixing crash which caused by wrong position calculation when enabling endless scroll
- Add ElevateScaleLayoutManager
- Fixing onPageSelected does not trigger when scrolling back distance equals zero
- Add RotateLayoutManager
support infinite scroll- optimize performance
- support indicator
- support item view with different size
- support other effects (long term subject)
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.