public class BannerLayoutManager
extends RecyclerView.LayoutManager
RecyclerView.LayoutManager which behaves like view pager.
Please make sure your child view have the same size.| Modifier and Type | Class and Description |
|---|---|
static interface |
BannerLayoutManager.OnPageChangeListener |
| Modifier and Type | Field and Description |
|---|---|
static int |
DETERMINE_BY_MAX_AND_MIN |
static int |
HORIZONTAL |
protected static int |
INVALID_SIZE |
protected int |
mDecoratedMeasurement |
protected int |
mDecoratedMeasurementInOther |
protected float |
mInterval |
protected float |
mOffset
The offset of property which will change while scrolling
|
protected OrientationHelper |
mOrientationHelper
Many calculations are made depending on orientation.
|
protected int |
mSpaceInOther |
protected int |
mSpaceMain |
static int |
VERTICAL |
| Constructor and Description |
|---|
BannerLayoutManager(android.content.Context context)
Creates a horizontal ViewPagerLayoutManager
|
BannerLayoutManager(android.content.Context context,
int orientation) |
BannerLayoutManager(android.content.Context context,
int orientation,
boolean reverseLayout) |
| Modifier and Type | Method and Description |
|---|---|
protected int |
calItemLeft(android.view.View itemView,
float targetOffset) |
protected int |
calItemTop(android.view.View itemView,
float targetOffset) |
boolean |
canScrollHorizontally() |
boolean |
canScrollVertically() |
int |
computeHorizontalScrollExtent(RecyclerView.State state) |
int |
computeHorizontalScrollOffset(RecyclerView.State state) |
int |
computeHorizontalScrollRange(RecyclerView.State state) |
int |
computeVerticalScrollExtent(RecyclerView.State state) |
int |
computeVerticalScrollOffset(RecyclerView.State state) |
int |
computeVerticalScrollRange(RecyclerView.State state) |
android.view.View |
findViewByPosition(int position) |
RecyclerView.LayoutParams |
generateDefaultLayoutParams() |
int |
getCurrentPosition() |
protected float |
getDistanceRatio() |
int |
getDistanceToBottom() |
boolean |
getEnableBringCenterToFront() |
boolean |
getInfinite() |
int |
getMaxVisibleItemCount()
Returns the max visible item count,
DETERMINE_BY_MAX_AND_MIN means it haven't been set now
And it will use maxRemoveOffset() and minRemoveOffset() to handle the range |
int |
getOffsetToCenter() |
int |
getOffsetToPosition(int position) |
int |
getOrientation()
Returns the current orientation of the layout.
|
boolean |
getRecycleChildrenOnDetach()
Returns whether LayoutManager will recycle its children when it is detached from
RecyclerView.
|
boolean |
getReverseLayout()
Returns if views are laid out from the opposite direction of the layout.
|
boolean |
getSmoothScrollbarEnabled()
Returns the current state of the smooth scrollbar feature.
|
int |
getTotalSpaceInOther() |
protected float |
maxRemoveOffset()
when the target offset reach this,
the view will be removed and recycled in
layoutItems(RecyclerView.Recycler) |
protected float |
minRemoveOffset()
when the target offset reach this,
the view will be removed and recycled in
layoutItems(RecyclerView.Recycler) |
void |
onAdapterChanged(RecyclerView.Adapter oldAdapter,
RecyclerView.Adapter newAdapter) |
boolean |
onAddFocusables(RecyclerView recyclerView,
java.util.ArrayList<android.view.View> views,
int direction,
int focusableMode) |
void |
onDetachedFromWindow(RecyclerView view,
RecyclerView.Recycler recycler) |
android.view.View |
onFocusSearchFailed(android.view.View focused,
int focusDirection,
RecyclerView.Recycler recycler,
RecyclerView.State state) |
void |
onLayoutChildren(RecyclerView.Recycler recycler,
RecyclerView.State state) |
void |
onLayoutCompleted(RecyclerView.State state) |
void |
onRestoreInstanceState(android.os.Parcelable state) |
android.os.Parcelable |
onSaveInstanceState() |
int |
scrollHorizontallyBy(int dx,
RecyclerView.Recycler recycler,
RecyclerView.State state) |
void |
scrollToPosition(int position) |
int |
scrollVerticallyBy(int dy,
RecyclerView.Recycler recycler,
RecyclerView.State state) |
void |
setCenterScale(float centerScale) |
void |
setDistanceToBottom(int mDistanceToBottom) |
void |
setEnableBringCenterToFront(boolean bringCenterToTop) |
void |
setInfinite(boolean enable) |
protected float |
setInterval() |
void |
setItemSpace(int itemSpace) |
protected void |
setItemViewProperty(android.view.View itemView,
float targetOffset) |
void |
setMaxVisibleItemCount(int mMaxVisibleItemCount)
Set the max visible item count,
DETERMINE_BY_MAX_AND_MIN means it haven't been set now
And it will use maxRemoveOffset() and minRemoveOffset() to handle the range |
void |
setMoveSpeed(float moveSpeed) |
void |
setOnPageChangeListener(BannerLayoutManager.OnPageChangeListener onPageChangeListener) |
void |
setOrientation(int orientation)
Sets the orientation of the layout.
|
void |
setRecycleChildrenOnDetach(boolean recycleChildrenOnDetach)
Set whether LayoutManager will recycle its children when it is detached from
RecyclerView.
|
void |
setReverseLayout(boolean reverseLayout)
Used to reverse item traversal and layout order.
|
void |
setSmoothScrollbarEnabled(boolean enabled)
When smooth scrollbar is enabled, the position and size of the scrollbar thumb is computed
based on the number of visible pixels in the visible items.
|
void |
setSmoothScrollInterpolator(android.view.animation.Interpolator smoothScrollInterpolator) |
protected void |
setUp()
You can set up your own properties here or change the exist properties like mSpaceMain and mSpaceInOther
|
protected float |
setViewElevation(android.view.View itemView,
float targetOffset)
cause elevation is not support below api 21,
so you can set your elevation here for supporting it below api 21
or you can just setElevation in
setItemViewProperty(View, float) |
void |
smoothScrollToPosition(RecyclerView recyclerView,
RecyclerView.State state,
int position) |
public static final int DETERMINE_BY_MAX_AND_MIN
public static final int HORIZONTAL
public static final int VERTICAL
protected static final int INVALID_SIZE
protected int mDecoratedMeasurement
protected int mDecoratedMeasurementInOther
protected int mSpaceMain
protected int mSpaceInOther
protected float mOffset
protected OrientationHelper mOrientationHelper
LinearLayoutManager make those decisions.
Based on mOrientation, an implementation is lazily created in
ensureLayoutState() method.protected float mInterval
public BannerLayoutManager(android.content.Context context)
public BannerLayoutManager(android.content.Context context,
int orientation)
orientation - Layout orientation. Should be HORIZONTAL or VERTICALpublic BannerLayoutManager(android.content.Context context,
int orientation,
boolean reverseLayout)
protected float getDistanceRatio()
protected float setInterval()
public void setItemSpace(int itemSpace)
public void setCenterScale(float centerScale)
public void setMoveSpeed(float moveSpeed)
protected void setItemViewProperty(android.view.View itemView,
float targetOffset)
protected float setViewElevation(android.view.View itemView,
float targetOffset)
setItemViewProperty(View, float)public RecyclerView.LayoutParams generateDefaultLayoutParams()
public boolean getRecycleChildrenOnDetach()
public void setRecycleChildrenOnDetach(boolean recycleChildrenOnDetach)
If you are using a RecyclerView.RecycledViewPool, it might be a good idea to set
this flag to true so that views will be available to other RecyclerViews
immediately.
Note that, setting this flag will result in a performance drop if RecyclerView is restored.
recycleChildrenOnDetach - Whether children should be recycled in detach or not.public void onDetachedFromWindow(RecyclerView view,
RecyclerView.Recycler recycler)
public android.os.Parcelable onSaveInstanceState()
public void onRestoreInstanceState(android.os.Parcelable state)
public boolean canScrollHorizontally()
getOrientation() is HORIZONTALpublic boolean canScrollVertically()
getOrientation() is VERTICALpublic int getOrientation()
HORIZONTAL or VERTICALsetOrientation(int)public void setOrientation(int orientation)
BannerLayoutManager
will do its best to keep scroll position.orientation - HORIZONTAL or VERTICALpublic int getMaxVisibleItemCount()
DETERMINE_BY_MAX_AND_MIN means it haven't been set now
And it will use maxRemoveOffset() and minRemoveOffset() to handle the rangepublic void setMaxVisibleItemCount(int mMaxVisibleItemCount)
DETERMINE_BY_MAX_AND_MIN means it haven't been set now
And it will use maxRemoveOffset() and minRemoveOffset() to handle the rangemMaxVisibleItemCount - Max visible item countpublic boolean getReverseLayout()
setReverseLayout(boolean)public void setReverseLayout(boolean reverseLayout)
For horizontal layouts, it depends on the layout direction.
When set to true, If android.support.v7.widget.RecyclerView is LTR, than it will
layout from RTL, if android.support.v7.widget.RecyclerView} is RTL, it will layout
from LTR.
public void setSmoothScrollInterpolator(android.view.animation.Interpolator smoothScrollInterpolator)
public void smoothScrollToPosition(RecyclerView recyclerView,
RecyclerView.State state,
int position)
public void scrollToPosition(int position)
public void onLayoutChildren(RecyclerView.Recycler recycler,
RecyclerView.State state)
public int getTotalSpaceInOther()
public void onLayoutCompleted(RecyclerView.State state)
public boolean onAddFocusables(RecyclerView recyclerView,
java.util.ArrayList<android.view.View> views,
int direction,
int focusableMode)
public android.view.View onFocusSearchFailed(android.view.View focused,
int focusDirection,
RecyclerView.Recycler recycler,
RecyclerView.State state)
protected void setUp()
public void onAdapterChanged(RecyclerView.Adapter oldAdapter,
RecyclerView.Adapter newAdapter)
public int computeHorizontalScrollOffset(RecyclerView.State state)
public int computeVerticalScrollOffset(RecyclerView.State state)
public int computeHorizontalScrollExtent(RecyclerView.State state)
public int computeVerticalScrollExtent(RecyclerView.State state)
public int computeHorizontalScrollRange(RecyclerView.State state)
public int computeVerticalScrollRange(RecyclerView.State state)
public int scrollHorizontallyBy(int dx,
RecyclerView.Recycler recycler,
RecyclerView.State state)
public int scrollVerticallyBy(int dy,
RecyclerView.Recycler recycler,
RecyclerView.State state)
protected int calItemLeft(android.view.View itemView,
float targetOffset)
protected int calItemTop(android.view.View itemView,
float targetOffset)
protected float maxRemoveOffset()
layoutItems(RecyclerView.Recycler)protected float minRemoveOffset()
layoutItems(RecyclerView.Recycler)public int getCurrentPosition()
public android.view.View findViewByPosition(int position)
public int getOffsetToCenter()
public int getOffsetToPosition(int position)
public void setOnPageChangeListener(BannerLayoutManager.OnPageChangeListener onPageChangeListener)
public void setInfinite(boolean enable)
public boolean getInfinite()
public int getDistanceToBottom()
public void setDistanceToBottom(int mDistanceToBottom)
public void setSmoothScrollbarEnabled(boolean enabled)
When smooth scrollbar is disabled, the position and size of the scrollbar thumb is based solely on the number of items in the mAdapter and the position of the visible items inside the mAdapter. This provides a stable scrollbar as the user navigates through a list of items with varying widths / heights.
enabled - Whether or not to enable smooth scrollbar.setSmoothScrollbarEnabled(boolean)public void setEnableBringCenterToFront(boolean bringCenterToTop)
public boolean getEnableBringCenterToFront()
public boolean getSmoothScrollbarEnabled()
setSmoothScrollbarEnabled(boolean)