Giter Site home page Giter Site logo

Comments (8)

imunique-ZJ avatar imunique-ZJ commented on May 26, 2024 1

Hooray!! It works!!

from multisnaprecyclerview.

TakuSemba avatar TakuSemba commented on May 26, 2024

Thank you for reporting. I will take a look.

from multisnaprecyclerview.

imunique-ZJ avatar imunique-ZJ commented on May 26, 2024

By the way, I use a custom LayoutManager and a custom ItemDecorator to achieve center focusing like the image above. After expand 1 more pixel for width in ItemDecoration, v2.0.1 will focus the last item as expected.

class CenteredItemDecoration: RecyclerView.ItemDecoration() {

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        // default offsets
        outRect.left = 0
        outRect.top = 0
        outRect.right = 0
        outRect.bottom = 0

        val itemWidth = view.resources.displayMetrics.widthPixels / 5
        view.updateLayoutParams<ViewGroup.LayoutParams> { width = itemWidth }

        val additionalOffset = view.resources.displayMetrics.widthPixels / 2 - itemWidth / 2
        when (parent.getChildAdapterPosition(view)) {
            0 -> outRect.left = additionalOffset
            (parent.layoutManager?.itemCount ?: 0) - 1 -> outRect.right = additionalOffset // +1 here will make v2.0.1 focus  last item
        }
    }
}

from multisnaprecyclerview.

imunique-ZJ avatar imunique-ZJ commented on May 26, 2024

Hi, any updates here?

from multisnaprecyclerview.

TakuSemba avatar TakuSemba commented on May 26, 2024

Sorry for the late reply.
Unfortunately, I could not reproduce it on my own.
Can you reproduce it on sample app in this repo?

from multisnaprecyclerview.

imunique-ZJ avatar imunique-ZJ commented on May 26, 2024

Hi, I tried the Horizontal RecyclerView of the sample app and change the first sample to 3 items and set msrv_gravity="center", msrv_interval="1" and added the CenteredItemDecoration I provided above, it worked as expected. However, if I remove the margin of the list item, it will fail to focus the last item.

item_horizontal.xml
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:orientation="horizontal"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_marginLeft="8dp" <!---- remove margin ---->
  android:layout_marginRight="8dp" <!---- remove margin ---->
  app:cardUseCompatPadding="true"
  >
    ...
</androidx.cardview.widget.CardView >

device-2020-01-16-142607

If I commented out the line

view.updateLayoutParams<ViewGroup.LayoutParams> { width = itemWidth }

it will focus the last item but not at the center of the item.
device-2020-01-16-142641

from multisnaprecyclerview.

TakuSemba avatar TakuSemba commented on May 26, 2024

Thank you for the information, I will try to look into it.

from multisnaprecyclerview.

TakuSemba avatar TakuSemba commented on May 26, 2024

I fixed it at the version of 2.0.2. 👍 Could you check if it does not happen?

from multisnaprecyclerview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.