Comments (18)
Hey!
If I understand right your issue so try to change this line in CarouselZoomPostLayoutListener:
final float translateXGeneral = child.getMeasuredWidth() * (1 - scale) / 2f;
to this one:
final float translateXGeneral = child.getMeasuredWidth() * (1 - scale) / 0.8f;
I use horizontal carousel and it's make the animation looks better and child views not overlapping centered view
from carousellayoutmanager.
Hi everybody,
Just remove calculateScrollForSelectingPosition() method call in CarouselLayoutManager can get rid of the jumping feel. Line 361,365 and 368.
I don't know whether this method is useful in other case, In my case,this method is unnecessary and cause the item jump to the center position while scrolling.
from carousellayoutmanager.
@red742652 Don't do that! It will cause problem when add, remove items!
refer this
from carousellayoutmanager.
Hi @jpvs0101
I don't want to remove calculateScrollForSelectingPosition method call because of this problem, but want to find a bug in jumping...
And thanks for your help and really active position!
from carousellayoutmanager.
@iamshajeer
What do you mean by "scrolling is not smooth" and "make it pixel by pixel"?
This is carousel layout. Don't understand what do you want to adjust. Can you make a picture?
from carousellayoutmanager.
Thanks for your concern. Issue is when you try to change(scroll) one recyclerview item to another the second item comes suddenly. Which is not smooth. May be I can create a gif and post very soon. Also is there any way to change the bottom position of the next and previous items ? I couldn't find anything. Please clarify.
from carousellayoutmanager.
@iamshajeer
Bottom and zoom of the next and previous items are controlled by CarouselZoomPostLayoutListener. Check its code. There are come Mathematics functions of zooming and positioning.
About not smooth animation.. not sure how you want it to look like.
from carousellayoutmanager.
@iamshajeer any update here? can you give me an example of such animation?
from carousellayoutmanager.
@mig35, I think he's talking about something like this, where the items should be going smoothly, similar to just a standard horizontal layout manager, but with all the utility methods that you guys provide (which is what I'm trying to figure out right now).
from carousellayoutmanager.
Hi @nachtien
as I can see all that we need to change is a Math algorithm in PostLayoutListener.
We provide only one variant with zoom and translate logic in CarouselLayoutManager/CarouselLayoutManager/carousel/src/main/java/com/azoft/carousellayoutmanager/CarouselZoomPostLayoutListener.java but anyone can build there own PostLayoutListener.
from carousellayoutmanager.
In addition to my previous answer you can change this line in CenterScrollListener:
recyclerView.smoothScrollBy(scrollNeeded, 0);
to this one:
recyclerView.smoothScrollBy(scrollNeeded, 0, new DecelerateInterpolator());
This one will slow down the animation on centered view and it will look better
from carousellayoutmanager.
Hi,
I have the somewhat same issue, Centre Image try to relocate to middle with a jerk, even it is calling
recyclerView.smoothScrollBy(scrollNeeded, 0);
in CenterScrollListener file.
from carousellayoutmanager.
Hi, the same here. Sometimes it scrolls smooth, sometime it "jumps" from one recycler item to another.
from carousellayoutmanager.
Hi, same here. I'm dealing the same issue with jumps. When scrolling second element to the centre position and sizes of the centre and the second elements becomes the same, second element just jumps to the centre position.
When itemSelectedListener works with UI or when adapter is loading images with Glide it starts jumping.
from carousellayoutmanager.
@mig35 @iamshajeer @nachtien @roman-inmanage @AnkitDApalya any update on this issue I am facing same
from carousellayoutmanager.
where is the complete code for removing that jumpy jerk, kindly i need it.
from carousellayoutmanager.
For all of those who are still interested in a solution.
First of all, there is no need to modify the source code! As @mig35 stated:
as I can see all that we need to change is a Math algorithm in PostLayoutListener.
Absolutely correct!
What was causing the jerking/jumping movement is the scale calculation. I created an implementation of PostLayoutListener
based on the one provided with the library (CarouselZoomPostLayoutListener
) and replaced the calculation of scale.
In my case, it was calculated as simple as: val scale = 1f - 0.17f * abs(itemPositionToCenterDiff)
Where 0.17f
is the value that tells in percentage how small next item will be relative to the previous one.
It works this way: the centre item is scaled 1:1 items to left and right of it will be 17% smaller; the next item to the left and right will be 34% smaller and so on.
Here is the full implementation in Kotlin of PostLayoutListener.
/**
* [PostLayoutListener] implementation used to translate and scale views.
*
* @param scaleMultiplier value used to scale items that move closer to the center or away from it.
* Centered item is presented in its original size (scaled as 1:1).
* Pass positive value to reduce item size relative to the centered one, negative to increase (centered item is always 1:1).
*/
class PostsCarouselZoomPostLayoutListener(private val scaleMultiplier: Float = 0.17f) : PostLayoutListener {
override fun transformChild(
@NonNull child: View,
itemPositionToCenterDiff: Float,
orientation: Int
): ItemTransformation {
val scale = 1f - scaleMultiplier * abs(itemPositionToCenterDiff)
// because scaling will make view smaller in its center, then we should move this item to the top or bottom to make it visible
val translateY: Float
val translateX: Float
if (CarouselLayoutManager.VERTICAL == orientation) {
val translateYGeneral = child.measuredHeight * (1 - scale) / 2f
translateY = Math.signum(itemPositionToCenterDiff) * translateYGeneral
translateX = 0f
} else {
val translateXGeneral = child.measuredWidth * (1 - scale) / 2f
translateX = Math.signum(itemPositionToCenterDiff) * translateXGeneral
translateY = 0f
}
return ItemTransformation(scale, scale, translateX, translateY)
}
}
from carousellayoutmanager.
Great thing @JeneaVranceanu .
I'm going to test your code and perhaps will add it as an other PostLayoutListener
from carousellayoutmanager.
Related Issues (20)
- How enable auto scroll HOT 1
- 请问怎么设置缩放大小?How do I set the zoom size?
- 你好,可以设置子view的高度或缩小比例吗?
- Click Listener
- Number of item count while scrolling
- Fatal Exception: java.lang.NullPointerException Attempt to read from field 'androidx.recyclerview.widget.RecyclerView$ViewFlinger androidx.recyclerview.widget.RecyclerView.mViewFlinger' on a null object reference HOT 5
- how Switch to increase transparency during sliding
- Consider migrating from jcenter HOT 5
- All items can be in a position from top to bottom HOT 2
- Gradient Color Background Items
- How to add item fade effect HOT 1
- How to disable smoothScrollToPosition HOT 8
- My app cant open in my andorid after build the app HOT 7
- can't display image with using <androidx.recyclerview.widget.RecyclerView>
- One swipe, many scrolling
- how does it look like ViewPager
- How to correctly offset elements? HOT 1
- No item visible
- Set item selected on initialization HOT 1
- Have you achieve to add dot indicator to your Carousel ?
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 carousellayoutmanager.