Comments (8)
Hooray!! It works!!
from multisnaprecyclerview.
Thank you for reporting. I will take a look.
from multisnaprecyclerview.
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.
Hi, any updates here?
from multisnaprecyclerview.
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.
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 >
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.
from multisnaprecyclerview.
Thank you for the information, I will try to look into it.
from multisnaprecyclerview.
I fixed it at the version of 2.0.2. 👍 Could you check if it does not happen?
from multisnaprecyclerview.
Related Issues (20)
- it is not available to set item which i want to set in center HOT 3
- The rolling speed is too slow, can you adjust the rolling speed? HOT 1
- Backward scrolling sometimes snaps twice HOT 9
- A warning appear. HOT 2
- Set snapGravity programmatically HOT 1
- Snap Programatically HOT 3
- How to center the visible items afte snapping/ HOT 1
- Any idea how to handle screen orientation? HOT 1
- Not able to show last item with gravity start HOT 1
- Alternatives to msrv_speed_ms_per_inch HOT 3
- Hi, thank you for the request. HOT 1
- New Feature as requirement HOT 5
- The application may be doing too much work on its main thread. HOT 1
- Richiejack32 HOT 1
- >for me
- Version 1.1.0 released, but code here shows it's 1.0.3 HOT 3
- Is it possible to snap every X views? HOT 2
- It's not available to fragment? HOT 5
- java.lang.IllegalArgumentException: other than LinearLayoutManger is not supported HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multisnaprecyclerview.