简体   繁体   中英

Resistance with scroll in HorizontalPager in Jetpack Compose

I have implemented HorizontalPager with TabRow in my project. My HorizontalPager uses default fling behaviour from PagerDefaults.flingBehavior(state) . I have not overridden the fling behavior.

This is how the code looks like:

    val pagerState = rememberPagerState()
    HorizontalPager(
                count = profileState.tabs.size,
                state = pagerState
            ) {..grid item..}

I have to scroll very hard to scroll between the pager items. I want the pager to scroll to next/previous screen on even slight scroll.

After debugging and logging, I found that initialVelocity in performFling method is coming out to be -0.0 (same for left and right fling) all the time for some reason.

You can use (with Accompanist version: accompanist-pager:0.24.8-beta):

  HorizontalPager(
        count = 3,
        state = pagerState,
        verticalAlignment = Alignment.Top,
        modifier = Modifier.fillMaxSize()
    )

In my case, there was a horizontal scrollable Row in the pager item. Make it unscrollable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM