Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

459
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda