Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saqib-github-commits/2daa7d0f00af9f6978640ee78d2c6f26 to your computer and use it in GitHub Desktop.
Save saqib-github-commits/2daa7d0f00af9f6978640ee78d2c6f26 to your computer and use it in GitHub Desktop.
@Composable
fun HorizontalPagerWithIndicatorsScreen() {
val images = listOf(
R.drawable.logo_android,
R.drawable.logo_kotlin,
R.drawable.logo_apple,
R.drawable.logo_fb,
R.drawable.logo_google,
)
Column {
HorizontalPagerWithIndicators(images)
}
}
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun HorizontalPagerWithIndicators(images: List<Int>) {
val pagerState = rememberPagerState()
Box(modifier = Modifier
.fillMaxWidth()
.height(300.dp)
) {
HorizontalPager(pageCount = 5, state = pagerState) {
Image(
painter = painterResource(id = images[it]),
contentScale = ContentScale.Crop,
contentDescription = "" )
}
HorizontalPagerIndicator(
modifier = Modifier
.align(Alignment.BottomCenter)
.padding(bottom = 10.dp),
pageCount = 5,
pagerState = pagerState,
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment