material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.37k stars 3.07k forks source link

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

Open Emplexx opened 11 months ago

Emplexx commented 11 months ago

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

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

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

dsn5ft commented 11 months ago

cc @hunterstich @imhappi