@@ -86,7 +86,7 @@ Next, set your `RecyclerView`s layout manager to a new `CarouselLayoutManager`.
86
86
android : clipToPadding =" false" />
87
87
```
88
88
89
- ``` kotlin
89
+ ``` kt
90
90
carouselRecyclerView.setLayoutManager(CarouselLayoutManager ())
91
91
```
92
92
@@ -114,7 +114,7 @@ by medium and small items, depending on the size of the `RecyclerView`
114
114
container.
115
115
116
116
You can use the multi-browse strategy by passing in no arguments to the
117
- CarouselLayoutManager constructor: ` new CarouselLayoutManager()` .
117
+ CarouselLayoutManager constructor: ` CarouselLayoutManager() ` .
118
118
119
119
## Hero strategy
120
120
@@ -140,14 +140,13 @@ carousels with `match_parent` as the width will have more and more large items
140
140
as the screen size grows.
141
141
142
142
You can use the hero strategy by passing in the strategy to the
143
- CarouselLayoutManager constructor: `new CarouselLayoutManager(new
144
- HeroStrategy())`.
143
+ CarouselLayoutManager constructor: ` CarouselLayoutManager(HeroStrategy()) ` .
145
144
146
145
With the hero strategy, it is recommended to use the ` CarouselSnapHelper ` to snap to the nearest item like so:
147
146
148
- ```
149
- SnapHelper snapHelper = new CarouselSnapHelper();
150
- snapHelper.attachToRecyclerView(carouselRecyclerView);
147
+ ``` kt
148
+ val snapHelper = CarouselSnapHelper ()
149
+ snapHelper.attachToRecyclerView(carouselRecyclerView)
151
150
```
152
151
153
152
## Fullscreen strategy
@@ -158,8 +157,8 @@ A fullscreen strategy shows one item at a time that takes up the entire space
158
157
of the carousel.
159
158
160
159
You can use the fullscreen strategy by passing in the strategy to the
161
- CarouselLayoutManager constructor: `new CarouselLayoutManager(new
162
- FullScreenStrategy())`.
160
+ CarouselLayoutManager constructor:
161
+ ` CarouselLayoutManager( FullScreenStrategy())` .
163
162
164
163
With the fullscreen strategy, it is recommended to use a vertical orientation
165
164
carousel by either setting the orientation on the CarouselLayoutManager with the
@@ -171,17 +170,9 @@ landscape in order to maintain the aspect ratios of your images.
171
170
It is also recommended to use the ` CarouselSnapHelper `
172
171
to snap to the nearest item like so:
173
172
174
- ```
175
- SnapHelper snapHelper = new CarouselSnapHelper();
176
- snapHelper.attachToRecyclerView(carouselRecyclerView);
177
- ```
178
-
179
- It is also recommended to use the ` CarouselSnapHelper `
180
- to snap to the nearest item like so:
181
-
182
- ```
183
- SnapHelper snapHelper = new CarouselSnapHelper();
184
- snapHelper.attachToRecyclerView(carouselRecyclerView);
173
+ ``` kt
174
+ val snapHelper = CarouselSnapHelper ()
175
+ snapHelper.attachToRecyclerView(carouselRecyclerView)
185
176
```
186
177
187
178
## Attributes
@@ -211,13 +202,12 @@ by setting an
211
202
[ ` onMaskChangedListener ` ] ( https://developer.android.com/reference/com/google/android/material/carousel/OnMaskChangedListener )
212
203
on your ` MaskableFrameLayout ` inside your ` RecyclerView.ViewHolder ` .
213
204
214
- ``` kotlin
215
- (viewHolder.itemView as MaskableFrameLayout ).setOnMaskChangedListener(
205
+ ``` kt
206
+ (viewHolder.itemView as MaskableFrameLayout ).setOnMaskChangedListener {
216
207
maskRect ->
217
208
// Any custom motion to run when mask size changes
218
- viewHolder.title.setTranslationX(maskRect.left);
219
- viewHolder.title.setAlpha(lerp(1F , 0F , 0F , 80F , maskRect.left));
220
- );
209
+ viewHolder.title.setTranslationX(maskRect.left)
210
+ viewHolder.title.setAlpha(lerp(1F , 0F , 0F , 80F , maskRect.left))
221
211
}
222
212
```
223
213
@@ -227,7 +217,7 @@ In the example above, a title is translated so it appears pinned to the left mas
227
217
228
218
You can control the alignment of the focal (large) items in the carousel by setting the ` app:carousel_alignment ` attribute on your RecyclerView, if you are also setting the RecyclerView's LayoutManager through ` app:layoutManager ` :
229
219
230
- ```
220
+ ``` xml
231
221
<androidx .recyclerview.widget.RecyclerView
232
222
...
233
223
app : layoutManager =" com.google.android.material.carousel.CarouselLayoutManager"
@@ -237,8 +227,8 @@ You can control the alignment of the focal (large) items in the carousel by sett
237
227
238
228
If CarouselLayoutManager is being set programmatically, you may set the alignment as well programmatically:
239
229
240
- ```
241
- carouselLayoutManager.setCarouselAlignment(CarouselLayoutManager.CENTER);
230
+ ``` kt
231
+ carouselLayoutManager.setCarouselAlignment(CarouselLayoutManager .CENTER )
242
232
```
243
233
244
234
By default, the focal alignment is start-aligned.
0 commit comments