Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

463
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!