material-components / material-components/material-components-android

[Carousel] Built-in way to set space between carousel items

Open
#3,922 1 comment 1 reaction 2 assignees Claimed by @hunterstich View on GitHub
feature request
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
The documented way of doing this is setting horizontal margins on the `MaskableFrameLayout` wrapping the carousel item. This however results in an issue where the left and right edges of the carousel (the way the user sees them) will constantly change as you scroll the carousel. For example, if the carousel recycler view has 16dp margins on the left and right, and the individual items have 4dp margins on left and right for 8dp of total space between, then as you scroll the carousel the actual visible space between the edge of the recycler view and the item will go back and forth between 16dp and 20dp (16+4), this issue becomes more obvious if you set larger margins on the item, for example 8dp on both sides.

Setting the margin only on one side of the item doesn't work because then the item will get slightly cut off on the opposite side of recycler view (see image, the right-most item is getting cut off)
![image](https://github.com/material-components/material-components-android/assets/64900852/0faeea38-2e21-4efc-a9e9-fd38491351ee)

Using the `ItemDecoration` API for this purpose also results in items getting cut off at the edges, and the decoration itself doesn't seem to play well with the carousel layout manager because the space between is not consistent (see image, left edge is getting cut off and the two spaces are different)
![image](https://github.com/material-components/material-components-android/assets/64900852/be43f5bd-47a1-4713-8d1b-89652523a6e9)

**Describe the solution you'd like**
An out of the box solution for setting space between items in a carousel that does not produce any of the issues described above

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.