0

I have migrated an app using androidx.viewpager.widget.ViewPager to Jetpack Compose with HorizontalPager from Accompanist. Viewpager had a method setPageMarginDrawable that allowed me to have a simple vertical divider between pages. I was able to emulate this by setting the color of the divider as the background of the HorizontalPager, and overriding this background on each page (by using Surface):

HorizontalPager(
    modifier = Modifier
        .fillMaxHeight()
        .background(MaterialTheme.colors.onSurface),
    count = 10,
    itemSpacing = 10.dp
) { page ->
    Surface(modifier = Modifier
        .fillMaxSize()) {
        Text(
            modifier = Modifier
                .wrapContentSize(),
            text = page.toString())
    }
}

Result

This approach generates some overdraw (as witnessed with Debug GPU overdraw from the Developer Options). I am wondering if I am missing a simpler and more efficient solution?

mtotschnig
  • 1,238
  • 10
  • 30

0 Answers0