public class CarouselLayoutManager
extends RecyclerView.LayoutManager
RecyclerView.LayoutManager that layout items like carousel.
Generally there is one center item and bellow this item there are maximum getMaxVisibleItems() items on each side of the center
item. By default getMaxVisibleItems() is MAX_VISIBLE_ITEMS.HORIZONTAL and VERTICAL orientations. ViewGroup.LayoutParams#MATCH_PARENT
for HORIZONTAL orientation.
So like layout_height is not ViewGroup.LayoutParams#MATCH_PARENT for VERTICAL| Modifier and Type | Class and Description |
|---|---|
protected static class |
CarouselLayoutManager.CarouselSavedState |
static interface |
CarouselLayoutManager.OnCenterItemSelectionListener |
static interface |
CarouselLayoutManager.PostLayoutListener
This interface methods will be called for each visible view item after general LayoutManager layout finishes.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
HORIZONTAL |
static int |
INVALID_POSITION |
static int |
MAX_VISIBLE_ITEMS |
static int |
VERTICAL |
| Constructor and Description |
|---|
CarouselLayoutManager(int orientation) |
CarouselLayoutManager(int orientation,
boolean circleLayout)
If circleLayout is true then all items will be in cycle.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addOnItemSelectionListener(CarouselLayoutManager.OnCenterItemSelectionListener onCenterItemSelectionListener) |
boolean |
canScrollHorizontally() |
boolean |
canScrollVertically() |
android.graphics.PointF |
computeScrollVectorForPosition(int targetPosition) |
protected double |
convertItemPositionDiffToSmoothPositionDiff(float itemPositionDiff)
Called during
getCardOffsetByPositionDiff(float) for better item movement. |
RecyclerView.LayoutParams |
generateDefaultLayoutParams() |
protected int |
getCardOffsetByPositionDiff(float itemPositionDiff)
Called during
fillData(RecyclerView.Recycler, RecyclerView.State) to calculate item offset from layout center line. |
int |
getCenterItemPosition() |
int |
getHeightNoPadding() |
int |
getMaxVisibleItems() |
protected int |
getOffsetCenterView() |
protected int |
getOffsetForCurrentView(android.view.View view) |
int |
getOrientation() |
protected int |
getScrollItemSize() |
int |
getWidthNoPadding() |
void |
onAdapterChanged(RecyclerView.Adapter oldAdapter,
RecyclerView.Adapter newAdapter) |
void |
onLayoutChildren(RecyclerView.Recycler recycler,
RecyclerView.State state) |
void |
onMeasure(RecyclerView.Recycler recycler,
RecyclerView.State state,
int widthSpec,
int heightSpec) |
void |
onRestoreInstanceState(android.os.Parcelable state) |
android.os.Parcelable |
onSaveInstanceState() |
void |
removeOnItemSelectionListener(CarouselLayoutManager.OnCenterItemSelectionListener onCenterItemSelectionListener) |
protected int |
scrollBy(int diff,
RecyclerView.Recycler recycler,
RecyclerView.State state)
This method is called from
scrollHorizontallyBy(int, RecyclerView.Recycler, RecyclerView.State) and
scrollVerticallyBy(int, RecyclerView.Recycler, RecyclerView.State) to calculate needed scroll that is allowed. |
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 |
setMaxVisibleItems(int maxVisibleItems)
Setup maximum visible (layout) items on each side of the center item.
|
void |
setPostLayoutListener(CarouselLayoutManager.PostLayoutListener postLayoutListener)
Setup
CarouselLayoutManager.PostLayoutListener for this LayoutManager. |
void |
smoothScrollToPosition(RecyclerView recyclerView,
RecyclerView.State state,
int position) |
public static final int HORIZONTAL
public static final int VERTICAL
public static final int INVALID_POSITION
public static final int MAX_VISIBLE_ITEMS
public CarouselLayoutManager(int orientation)
orientation - should be VERTICAL or HORIZONTALpublic CarouselLayoutManager(int orientation,
boolean circleLayout)
orientation - should be VERTICAL or HORIZONTALcircleLayout - true for enabling circleLayoutpublic void setPostLayoutListener(CarouselLayoutManager.PostLayoutListener postLayoutListener)
CarouselLayoutManager.PostLayoutListener for this LayoutManager.
Its methods will be called for each visible view item after general LayoutManager layout finishes. postLayoutListener - listener for item layout changes. Can be null.public void setMaxVisibleItems(int maxVisibleItems)
maxVisibleItems - should be great then 0, if bot an IllegalAccessException will be thrownpublic int getMaxVisibleItems()
setMaxVisibleItems(int)public RecyclerView.LayoutParams generateDefaultLayoutParams()
public int getOrientation()
VERTICAL,
HORIZONTALpublic boolean canScrollHorizontally()
public boolean canScrollVertically()
public int getCenterItemPosition()
public void addOnItemSelectionListener(CarouselLayoutManager.OnCenterItemSelectionListener onCenterItemSelectionListener)
onCenterItemSelectionListener - listener that will trigger when ItemSelectionChanges. can't be nullpublic void removeOnItemSelectionListener(CarouselLayoutManager.OnCenterItemSelectionListener onCenterItemSelectionListener)
onCenterItemSelectionListener - listener that was previously added by addOnItemSelectionListener(OnCenterItemSelectionListener)public void scrollToPosition(int position)
public void smoothScrollToPosition(RecyclerView recyclerView,
RecyclerView.State state,
int position)
public android.graphics.PointF computeScrollVectorForPosition(int targetPosition)
public int scrollVerticallyBy(int dy,
RecyclerView.Recycler recycler,
RecyclerView.State state)
public int scrollHorizontallyBy(int dx,
RecyclerView.Recycler recycler,
RecyclerView.State state)
protected int scrollBy(int diff,
RecyclerView.Recycler recycler,
RecyclerView.State state)
scrollHorizontallyBy(int, RecyclerView.Recycler, RecyclerView.State) and
scrollVerticallyBy(int, RecyclerView.Recycler, RecyclerView.State) to calculate needed scroll that is allowed. diff - distance that we want to scroll byrecycler - Recycler to use for fetching potentially cached views for a positionstate - Transient state of RecyclerViewpublic void onMeasure(RecyclerView.Recycler recycler,
RecyclerView.State state,
int widthSpec,
int heightSpec)
public void onAdapterChanged(RecyclerView.Adapter oldAdapter,
RecyclerView.Adapter newAdapter)
public void onLayoutChildren(RecyclerView.Recycler recycler,
RecyclerView.State state)
public int getWidthNoPadding()
public int getHeightNoPadding()
protected int getCardOffsetByPositionDiff(float itemPositionDiff)
fillData(RecyclerView.Recycler, RecyclerView.State) to calculate item offset from layout center line. convertItemPositionDiffToSmoothPositionDiff(float) * (size off area above center item when it is on the center). itemPositionDiff - current item difference with layout center line. if this is 0, then this item center is in layout center line.
if this is 1 then this item is bellow the layout center line in the full item size distance.protected double convertItemPositionDiffToSmoothPositionDiff(float itemPositionDiff)
getCardOffsetByPositionDiff(float) for better item movement. itemPositionDiff - current item difference with layout center line. if this is 0, then this item center is in layout center line.
if this is 1 then this item is bellow the layout center line in the full item size distance.getCardOffsetByPositionDiff(float)protected int getScrollItemSize()
public android.os.Parcelable onSaveInstanceState()
public void onRestoreInstanceState(android.os.Parcelable state)
protected int getOffsetCenterView()
protected int getOffsetForCurrentView(android.view.View view)