Skip to content

Commit ec509cc

Browse files
imhappiraajkumars
authored andcommittedJun 27, 2023
[Carousel][Docs] Update docs to include hero variant
PiperOrigin-RevId: 543488844
1 parent 6b48d3b commit ec509cc

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed
 

‎docs/components/Carousel.md

+51-6
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ page.
2828

2929
Carousel is built on top of `RecyclerView`. To learn how to use `RecyclerView` to display a list of items, please see [Create dynamic lists with RecyclerView](https://developer.android.com/develop/ui/views/layout/recyclerview).
3030

31-
## Multi-browse carousels
32-
33-
A multi-browse carousel allows quick browsing of many small items, like a photo thumbnail gallery. A start-aligned, multi-browse carousel is the default carousel.
34-
35-
To turn a horizontal list into a multi-browse carousel, first wrap your `RecyclerView`'s item layout in a `MaskableFrameLayout`. `MaskableFrameLayout` is a `FrameLayout` that is able to mask (clip) itself, and its children, to a percentage of its width. When a mask is set to 0%, the the entire view is visible in its original, "unmaksed" width. As a mask approaches 100%, the edges of the view begin to crop in towards the center, leaving a narrower and narrower sliver of the original view visible. Carousel masks and unmasks items as they are scrolled across the viewport to create a stylized look and feel.
31+
To turn a horizontal list into a carousel, first wrap your `RecyclerView`'s item layout in a `MaskableFrameLayout`. `MaskableFrameLayout` is a `FrameLayout` that is able to mask (clip) itself, and its children, to a percentage of its width. When a mask is set to 0%, the the entire view is visible in its original, "unmasked" width. As a mask approaches 100%, the edges of the view begin to crop in towards the center, leaving a narrower and narrower sliver of the original view visible. Carousel masks and unmasks items as they are scrolled across the viewport to create a stylized look and feel.
3632

3733
```xml
3834
<com.google.android.material.carousel.MaskableFrameLayout
@@ -71,7 +67,56 @@ Next, set your `RecyclerView`s layout manager to a new `CarouselLayoutManager`.
7167
carouselRecyclerView.setLayoutManager(CarouselLayoutManager())
7268
```
7369

74-
These are the basic steps to create a carousel with large items at the start of the list followed by medium and small items, depending on the size of the `RecyclerView` container.
70+
These are the basic steps to create a carousel. The look of the carousel depends
71+
on which carousel strategy you are using; you can have a
72+
[multi-browse strategy](#multi-browse-strategy) or
73+
[hero strategy](#hero-strategy).
74+
75+
## Multi-browse strategy
76+
77+
![A contained, multi-browse Carousel](assets/carousel/multibrowse.png)
78+
79+
A multi-browse strategy allows quick browsing of many small items, like a photo
80+
thumbnail gallery. A start-aligned, multi-browse strategy is the default
81+
strategy for the carousel.
82+
83+
With a multi-browse strategy, large items are at the start of the list followed
84+
by medium and small items, depending on the size of the `RecyclerView`
85+
container.
86+
87+
You can use the multi-browse strategy by passing in no arguments to the
88+
CarouselLayoutManager constructor: `new CarouselLayoutManager()`.
89+
90+
## Hero strategy
91+
92+
![A contained, hero Carousel](assets/carousel/hero.png)
93+
94+
A hero strategy highlights large content, like movies and other media, for more
95+
considered browsing and selection. It draws attention and focus to a main
96+
carousel item while hinting at the next item in line.
97+
98+
With a hero strategy, typically there is one large item is at the start of the
99+
list followed by a small item. When there is one large item, the large item
100+
takes up the entire size of the `RecyclerView` container, save some space for
101+
the small item.
102+
103+
There may be more than one large item depending on the dimensions of the
104+
carousel. On a horizontal carousel, the width of a large item will maximally be
105+
twice its height, and vice versa for vertical carousels. More large items are
106+
added when the maximum large item size has been reached. For example, horizontal
107+
carousels with `match_parent` as the width will have more and more large items
108+
as the screen size grows.
109+
110+
You can use the hero strategy by passing in the strategy to the
111+
CarouselLayoutManager constructor: `new CarouselLayoutManager(new
112+
HeroStrategy())`.
113+
114+
With the hero strategy, it is recommended to use the `CarouselSnapHelper` to snap to the nearest item like so:
115+
116+
```
117+
SnapHelper snapHelper = new CarouselSnapHelper();
118+
snapHelper.attachToRecyclerView(carouselRecyclerView);
119+
```
75120

76121
## Customizing carousel
77122

557 KB
Loading
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.