Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

423
Visualizações
How to set a threshold for LazyColumn/ViewPager before starting to scroll?

I'm using the experimental viewpager for Jetpack compose which is built upon LazyColumn/Row.

What I'm trying to do is to set some threshold of how much I need to move my finger before it starts to scroll to next page. The default behaviour is that as soon as I move my finger it starts to scroll, but I want to have a larger threshold of how much I need to move the finger before any visual scrolling occur. I've looked at the FlingBehaviour parameter, but I don't see how to use that to accomplish what I want. (Or at least add some more "resistance" to flip between the pages, so it's not so sensitive)

Have you got any ideas?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This threshold is controlled by the flingBehavior argument.

PagerDefaults.flingBehavior(pagerState) provides paging work, currently only animations are configurable, so you can't just provide your own instead behavior instead. But you can wrap it like this:

private class FlingBehaviourMultiplier(
    private val multiplier: Float,
    private val baseFlingBehavior: FlingBehavior
) : FlingBehavior {
    override suspend fun ScrollScope.performFling(initialVelocity: Float): Float {
        return with(baseFlingBehavior) {
            performFling(initialVelocity * multiplier)
        }
    }
}

@Composable
fun rememberFlingBehaviorMultiplier(
    multiplier: Float,
    baseFlingBehavior: FlingBehavior
): FlingBehavior = remember(multiplier, baseFlingBehavior) {
    FlingBehaviourMultiplier(multiplier, baseFlingBehavior)
}

Usage:

val pagerState = rememberPagerState()
HorizontalPager(
    count = 10,
    state = pagerState,
    flingBehavior = rememberFlingBehaviorMultiplier(
        multiplier = 0.5f,
        baseFlingBehavior = PagerDefaults.flingBehavior(pagerState)
    ),
    modifier = Modifier
) { page ->
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda