|
28 | 28 |
|
29 | 29 | 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).
|
30 | 30 |
|
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. |
36 | 32 |
|
37 | 33 | ```xml
|
38 | 34 | <com.google.android.material.carousel.MaskableFrameLayout
|
@@ -71,7 +67,56 @@ Next, set your `RecyclerView`s layout manager to a new `CarouselLayoutManager`.
|
71 | 67 | carouselRecyclerView.setLayoutManager(CarouselLayoutManager())
|
72 | 68 | ```
|
73 | 69 |
|
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 | + |
| 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 | + |
| 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 | +``` |
75 | 120 |
|
76 | 121 | ## Customizing carousel
|
77 | 122 |
|
|
0 commit comments