androidx.compose.material3.carousel

HorizontalUncontainedCarousel

Composable function

One of the carousel types. It works like HorizontalMultiBrowseCarousel. Only the parameters that differ are described here.

All items have the same width. Items at the edge are cut off.

Items of the same width
Items of the same width
val colors = listOf(Color(0xFF8E6CEF), Color(0xFFEF6C8E), Color(0xFF6CB4EF), Color(0xFF6CEF9B))
HorizontalUncontainedCarousel(
    state = rememberCarouselState { colors.size },
    itemWidth = 150.dp,
    itemSpacing = 8.dp,
    modifier = Modifier.width(360.dp).height(160.dp),
) { index ->
    Box(Modifier.fillMaxSize().maskClip(MaterialTheme.shapes.extraLarge).background(colors[index]))
}

Parameters

@Composable
fun HorizontalUncontainedCarousel(
    state: CarouselState,
    itemWidth: Dp,
    modifier: Modifier = Modifier,
    itemSpacing: Dp = 0.dp,
    flingBehavior: TargetedFlingBehavior = CarouselDefaults.noSnapFlingBehavior(),
    userScrollEnabled: Boolean = true,
    contentPadding: PaddingValues = PaddingValues(0.dp),
    content: @Composable CarouselItemScope.(itemIndex: Int) -> Unit,
)

itemWidth: DpRequired

The width of every item in an uncontained carousel.

Defaults that differ from HorizontalMultiBrowseCarousel:

Same as in HorizontalMultiBrowseCarousel: state, modifier, itemSpacing, flingBehavior, userScrollEnabled, contentPadding, content.

Carousel types