# CarouselLayoutManager

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/carousel/CarouselLayoutManager.java)

*** ** * ** ***


```
public class CarouselLayoutManager implements Carousel
```

<br />

*** ** * ** ***

A LayoutManager that can mask and offset items along the scrolling axis, creating a unique list optimized for a stylized viewing experience.

`https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager` requires all children to use `https://developer.android.com/reference/com/google/android/material/carousel/MaskableFrameLayout` as their root ViewGroup.

Note that when Carousel measures and lays out items, the first item in the adapter will be measured and it's desired size will be used to determine an appropriate size for all items in the carousel.

For more information, see the [component developer guidance](https://github.com/material-components/material-components-android/blob/master/docs/components/Carousel.md) and [design guidelines](https://material.io/components/carousel/overview).

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#ALIGNMENT_CENTER() = 1` Aligns large items to the center of the carousel. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#ALIGNMENT_START() = 0` Aligns large items to the start of the carousel. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#HORIZONTAL()` Horizontal orientation for Carousel. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#VERTICAL()` Vertical orientation for Carousel. |

| ### Public fields |
|---|---|
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#carouselAlignment()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#CarouselLayoutManager()()` |
| `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#CarouselLayoutManager(com.google.android.material.carousel.CarouselStrategy)(https://developer.android.com/reference/com/google/android/material/carousel/CarouselStrategy strategy)` |
| `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#CarouselLayoutManager(com.google.android.material.carousel.CarouselStrategy,int)(https://developer.android.com/reference/com/google/android/material/carousel/CarouselStrategy strategy, int orientation)` |
| `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#CarouselLayoutManager(Context,AttributeSet,int,int)( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes )` |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#canScrollHorizontally()()` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#canScrollVertically()()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeHorizontalScrollExtent(State)(State state)` Compute the extent of the horizontal scrollbar thumb. |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeHorizontalScrollOffset(State)(State state)` Calculate the offset of the horizontal scrollbar thumb within the horizontal range. |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeHorizontalScrollRange(State)(State state)` Compute the horizontal range represented by the horizontal scroll bars. |
| `PointF` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeScrollVectorForPosition(int)(int targetPosition)` |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeVerticalScrollExtent(State)(State state)` |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeVerticalScrollOffset(State)(State state)` |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeVerticalScrollRange(State)(State state)` |
| `LayoutParams` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#generateDefaultLayoutParams()()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#getCarouselAlignment()()` Gets the alignment of the carousel. |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#getContainerHeight()()` Gets the height of the carousel container. |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#getContainerWidth()()` Gets the width of the carousel container. |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#getDecoratedBoundsWithMargins(View,Rect)(View view, Rect outBounds)` Returns the masked, decorated bounds with margins for `view`. |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#getOrientation()()` Returns the current orientation of the layout. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#isAutoMeasureEnabled()()` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#isHorizontal()()` Whether or not the orientation is horizontal. |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#measureChildWithMargins(View,int,int)(View child, int widthUsed, int heightUsed)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#notifyItemSizeChanged()()` Recalculates the internal state of the Carousel based on the size of the items. |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#onAttachedToWindow(RecyclerView)(RecyclerView view)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#onDetachedFromWindow(RecyclerView,Recycler)(RecyclerView view, Recycler recycler)` |
| `View` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#onFocusSearchFailed(View,int,Recycler,State)( View focused, int focusDirection, Recycler recycler, State state )` |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#onInitializeAccessibilityEvent(AccessibilityEvent)(AccessibilityEvent event)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#onItemsAdded(RecyclerView,int,int)( RecyclerView recyclerView, int positionStart, int itemCount )` |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#onItemsChanged(RecyclerView)(RecyclerView recyclerView)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#onItemsRemoved(RecyclerView,int,int)( RecyclerView recyclerView, int positionStart, int itemCount )` |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#onLayoutChildren(Recycler,State)(Recycler recycler, State state)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#onLayoutCompleted(State)(State state)` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#requestChildRectangleOnScreen(RecyclerView,View,Rect,boolean,boolean)( RecyclerView parent, View child, Rect rect, boolean immediate, boolean focusedChildVisible )` |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#scrollHorizontallyBy(int,Recycler,State)(int dx, Recycler recycler, State state)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#scrollToPosition(int)(int position)` |
| `int` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#scrollVerticallyBy(int,Recycler,State)(int dy, Recycler recycler, State state)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#setCarouselAlignment(int)(int alignment)` Sets the alignment of the focal items in the carousel. |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#setCarouselStrategy(com.google.android.material.carousel.CarouselStrategy)(https://developer.android.com/reference/com/google/android/material/carousel/CarouselStrategy carouselStrategy)` Sets the `https://developer.android.com/reference/com/google/android/material/carousel/CarouselStrategy` used by this layout manager to mask and offset child views as they move along the scrolling axis. |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#setOrientation(int)(int orientation)` Sets the orientation of the layout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#smoothScrollToPosition(RecyclerView,State,int)( RecyclerView recyclerView, State state, int position )` |

| ### Inherited methods |
|---|
| From [com.google.android.material.carousel.Carousel](https://developer.android.com/reference/com/google/android/material/carousel/Carousel) |---|---| | `abstract int` | `https://developer.android.com/reference/com/google/android/material/carousel/Carousel#getItemCount()()` Gets the number of items in the carousel. | |

## Constants

### ALIGNMENT_CENTER

```
public static final int ALIGNMENT_CENTER = 1
```

Aligns large items to the center of the carousel.

### ALIGNMENT_START

```
public static final int ALIGNMENT_START = 0
```

Aligns large items to the start of the carousel.

### HORIZONTAL

```
public static final int HORIZONTAL
```

Horizontal orientation for Carousel.

### VERTICAL

```
public static final int VERTICAL
```

Vertical orientation for Carousel.

## Public fields

### carouselAlignment

```
public int carouselAlignment
```

## Public constructors

### CarouselLayoutManager

```
public CarouselLayoutManager()
```

### CarouselLayoutManager

```
public CarouselLayoutManager(CarouselStrategy strategy)
```

### CarouselLayoutManager

```
public CarouselLayoutManager(CarouselStrategy strategy, int orientation)
```

### CarouselLayoutManager

```
public CarouselLayoutManager(
    Context context,
    AttributeSet attrs,
    int defStyleAttr,
    int defStyleRes
)
```

## Public methods

### canScrollHorizontally

```
public boolean canScrollHorizontally()
```

### canScrollVertically

```
public boolean canScrollVertically()
```

### computeHorizontalScrollExtent

```
public int computeHorizontalScrollExtent(State state)
```

Compute the extent of the horizontal scrollbar thumb. This is the size of the thumb inside the scrollbar track.

This method can return an arbitrary unit as long as the unit is shared across `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeHorizontalScrollExtent(State)` and `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeHorizontalScrollOffset(State)`.

### computeHorizontalScrollOffset

```
public int computeHorizontalScrollOffset(State state)
```

Calculate the offset of the horizontal scrollbar thumb within the horizontal range. This is the position of the thumb within the scrollbar track.

This is also used for accessibility when scrolling to give auditory feedback about the current scroll position within the total range.

This method can return an arbitrary unit as long as the unit is shared across `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeHorizontalScrollExtent(State)` and `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeHorizontalScrollRange(State)`.

### computeHorizontalScrollRange

```
public int computeHorizontalScrollRange(State state)
```

Compute the horizontal range represented by the horizontal scroll bars. This is the total length of the scrollbar track within the range.

This method can return an arbitrary unit as long as the unit is shared across `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeHorizontalScrollExtent(State)` and `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#computeHorizontalScrollOffset(State)`.

### computeScrollVectorForPosition

```
public PointF computeScrollVectorForPosition(int targetPosition)
```

### computeVerticalScrollExtent

```
public int computeVerticalScrollExtent(State state)
```

### computeVerticalScrollOffset

```
public int computeVerticalScrollOffset(State state)
```

### computeVerticalScrollRange

```
public int computeVerticalScrollRange(State state)
```

### generateDefaultLayoutParams

```
public LayoutParams generateDefaultLayoutParams()
```

### getCarouselAlignment

```
public int getCarouselAlignment()
```

Gets the alignment of the carousel.

### getContainerHeight

```
public int getContainerHeight()
```

Gets the height of the carousel container.

### getContainerWidth

```
public int getContainerWidth()
```

Gets the width of the carousel container.

### getDecoratedBoundsWithMargins

```
public void getDecoratedBoundsWithMargins(View view, Rect outBounds)
```

Returns the masked, decorated bounds with margins for `view`.

Note that this differs from the super method which returns the fully unmasked bounds of `view`.

Getting the masked, decorated bounds is useful for item decorations and other associated classes which need the actual visual bounds of an item in the RecyclerView. If the full, unmasked bounds is needed, see getDecoratedBoundsWithMargins.

| Parameters |
|---|---|
| `View view` | the view element to check |
| `Rect outBounds` | a rect that will receive the bounds of the element including its maks, decoration, and margins. |

### getOrientation

```
public int getOrientation()
```

Returns the current orientation of the layout.

| Returns |
|---|---|
| `int` | Current orientation, either `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#HORIZONTAL()` or `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#VERTICAL()` |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#setOrientation(int)` |   |

### isAutoMeasureEnabled

```
public boolean isAutoMeasureEnabled()
```

### isHorizontal

```
public boolean isHorizontal()
```

Whether or not the orientation is horizontal.

### measureChildWithMargins

```
public void measureChildWithMargins(View child, int widthUsed, int heightUsed)
```

### notifyItemSizeChanged

```
public void notifyItemSizeChanged()
```

Recalculates the internal state of the Carousel based on the size of the items. This should be called whenever the size of the items is changed.

### onAttachedToWindow

```
public void onAttachedToWindow(RecyclerView view)
```

### onDetachedFromWindow

```
public void onDetachedFromWindow(RecyclerView view, Recycler recycler)
```

### onFocusSearchFailed

```
public View onFocusSearchFailed(
    View focused,
    int focusDirection,
    Recycler recycler,
    State state
)
```

### onInitializeAccessibilityEvent

```
public void onInitializeAccessibilityEvent(AccessibilityEvent event)
```

### onItemsAdded

```
public void onItemsAdded(
    RecyclerView recyclerView,
    int positionStart,
    int itemCount
)
```

### onItemsChanged

```
public void onItemsChanged(RecyclerView recyclerView)
```

### onItemsRemoved

```
public void onItemsRemoved(
    RecyclerView recyclerView,
    int positionStart,
    int itemCount
)
```

### onLayoutChildren

```
public void onLayoutChildren(Recycler recycler, State state)
```

### onLayoutCompleted

```
public void onLayoutCompleted(State state)
```

### requestChildRectangleOnScreen

```
public boolean requestChildRectangleOnScreen(
    RecyclerView parent,
    View child,
    Rect rect,
    boolean immediate,
    boolean focusedChildVisible
)
```

### scrollHorizontallyBy

```
public int scrollHorizontallyBy(int dx, Recycler recycler, State state)
```

### scrollToPosition

```
public void scrollToPosition(int position)
```

### scrollVerticallyBy

```
public int scrollVerticallyBy(int dy, Recycler recycler, State state)
```

### setCarouselAlignment

```
public void setCarouselAlignment(int alignment)
```

Sets the alignment of the focal items in the carousel.

### setCarouselStrategy

```
public void setCarouselStrategy(CarouselStrategy carouselStrategy)
```

Sets the `https://developer.android.com/reference/com/google/android/material/carousel/CarouselStrategy` used by this layout manager to mask and offset child views as they move along the scrolling axis.

### setOrientation

```
public void setOrientation(int orientation)
```

Sets the orientation of the layout.

| Parameters |
|---|---|
| `int orientation` | `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#HORIZONTAL()` or `https://developer.android.com/reference/com/google/android/material/carousel/CarouselLayoutManager#VERTICAL()` |

### smoothScrollToPosition

```
public void smoothScrollToPosition(
    RecyclerView recyclerView,
    State state,
    int position
)
```