Search code examples
androidkotlinandroid-jetpack-composeviewpagerindicatorjetpack-compose-accompanist

How do I position ViewPager Indicator CenterHorizontally in JetPack Compose


I'm practicing ViewPager in JetPack compose which is experimental right now.

I was able to successfully make a basic view pager, but when trying to add an indicator, I get an error: Cannot access 'ColumnScopeInstance': it is internal in 'androidx.compose.foundation.layout'

Indicator code; (please keep in keep I already imported it) enter image description here

I tried looking for answers, I found a similar problem problem here on stackOverFlow, but I don't understand.

I also found out that I could only use horizontalAlignment = Alignment.CenterHorizontally in a column.

To ask bluntly, How do I position ViewPager Indicator Center Horizontally.

And I followed the procedure on the official document for pager indicator, I don't know what I'm missing.

I'm highly open to Ideas. Thanks to you in Advance. \If you details is needed I'm more than happy to provide.


Solution

  • alignment and arrangement depend on the parent's view. for example if you're using 'HorizontalPagerIndicator' inside of a box, you can use:

    Box(contentAlignment = Alignment.Center) {....}
    

    otherwise, if your parent view is Column, I suggest doing it this way:

     Column(
            modifier = ....,
            horizontalAlignment = Alignment.CenterHorizontally
     ) {...}
    

    or for Row:

    Row( 
        modifier = ....,
        horizontalArrangement = Arrangement.Center
    ) {...}