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

467
Visualizações
Scaling center item in RecyclerView

When scrolling in a RecyclerView, I want to achieve something like this: enter image description here

Where the center item is scaled bigger than the other items. I've found a way to scale all the items, or what is called a Carousel Effect. But that is not what I want. I want to scale only the center item, and keep the other items their default size.

this is what I've found on other answers:

override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
    val snapHelper = LinearSnapHelper()
    snapHelper.attachToRecyclerView(recyclerView)

    recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
        override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
            val layoutManager = recyclerView.layoutManager!!
            val midpoint = layoutManager.width / 2f
            val distance = shrinkDistance * midpoint

            for (i in 0 until layoutManager.childCount) {
                val child = layoutManager.getChildAt(i)!!
                val childMidpoint = (layoutManager.getDecoratedRight(child) + layoutManager.getDecoratedLeft(child)) / 2f
                val d = Math.min(distance, Math.abs(midpoint - childMidpoint))
                val scale = 1 + -shrinkAmount * d / distance
                child.scaleX = scale
                child.scaleY = scale
            }
        }
    })
}

As I said, this scales all the visible items, where I only want to zoom the center item.

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

0

You could give the middle child different scaling.

Calculate the middle child from childCount and use a different scaling for it than the others.

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