I'm trying to achieve the effect that the Google+ Android app has where there is a View that sits at the bottom of the screen, and when the user scrolls the ListView that sits behind it UP the View animates down, off screen. When the user scrolls the ListView down, even slightly, the View animates back up, on screen.
I've set up a GestureDetector, that is giving me callbacks for the scroll event on my ListView, and the callbacks are constant as I scroll so I know that part is working.
In my callback I'm trying to use the ViewPropertyAnimator to animate my y value as such:
headerView.animate().yBy(distanceY).start();
Nothing happens until I stop scrolling. Is there any way to throw this animation in with the ListView scroll on the UI thread? I get the feeling it's waiting.
I've been fighting this one also. The trick I ended up using was to replace
headerView.animate().yBy(distanceY).start();
with
headerView.setTranslationY(floatValue);
Hope this helps!
Related
I am looking for a way to dismiss RecyclerView when it is scrolled over bounds. Effect would be similar to Google Maps.
I have RecyclerView with top padding so scrolling content works visually properly but when I scroll down to RecyclerView top I would like to start dragging the whole RecyclerView down and eventually hide it.
Is this achievable with ViewDragHelper somehow programmatically intercepting the touch and start dragging it, I've been trying to force the drag with no success.
Thanks.
I want to animate the RecyclerView scrolling. I don't want to animate adding or removal of items but rather animate items which are on screen, i.e visible items. What I want is, item settle down smoothly when scrolling is about to finish. I am not sure what approach should I take or how this can be done. I have tried following till now
Using RecyclerView.OnScrollListener, when I get onScrolled callback, I find visible items & animate them upside or downside based on scroll direction. But this approach is no-where near to perfect & many times when scrolling fast, some visible views are null so animation doesn't apply on them & it looks weird.
Tried to animate visible items when I receive SCROLL_STATE_IDLE. But there's noticeable delay for a fraction of second when scrolling is finished & then items animate. It doesn't look natural
Tried to figure out when RecyclerView scrolling is "about to" finish so I can start animation to mimic continuity of animation with scrolling. But didn't get success in identifying reliably that scrolling is about to finish.
Instead of above a little complex ways that doen't work the way I need, I wonder if there is any other way like creating custom LayoutManagerwhere I can override the each item scrolling so that it settle to it's aimed position smoothly?
Edit: Here's something very close to what I wanted
I'm trying to do a recycler view animation on scroll, but im struggling to get it started.
Basically, the animation will happen on scroll and always on the first visible child (and only on this one). When the user scrolls the recycler view, second item should overlap the first, and the first will slowly fade out. reverse animation when sliding down.
In short, when the list scroll top for example, when the first item goes offscreen and want to change that behaviour. Instead of going offscreen, it slowly fades based on scroll dY and stay in the same position.
Any hints would be much appreciated.
I think this answer may can help you. I used code like this in my app and work smootly.
https://stackoverflow.com/a/29714138/2971619
Hope to be usefull for you too!
I have a ViewPager widget in every row of a ListView. This provides a shelf-like UI, so the user can scroll around searching for a shelf vertically, and then scroll horizontally amongst the contents of a shelf. This works.
But the scrolling experience is terrible: if I start to drag a shelf's ViewPager, scroll it horizontally, and accidentally drag a bit upwards/downwards, then the ListView "traps" this dragging action, and start to scroll vertically, ending my horizontal drag. In this state, the drag action won't "return" to the ViewPager, the ListView has it, and that's it. I have to start another drag action to affect the ViewPager again. So I guess the ListView has precedence in these cases.
How can this be fixed? I'd like to achieve the exact opposite: If the ViewPager inside a list row starts reacting to a horizontal drag, then it should trap that action, and this drag should stop affecting the ListView, no matter how the user moves his/her finger vertically. Can this be done?
I've found a solution in this thread. There the problem is to handle touch events properly for a HorizontalScrollView inside a regular ScrollView, but the solution to that problem seems to apply to this one too.
I have a ScrollView which has two hidden images, one at the top and one at the bottom. In between there is a bunch of visible content.
What I need to do is make these images hidden by default but when you scroll all the way up or all the way down you could see them as you're scrolling. But then as soon as you stop scrolling it should bounce back to the visible area so that the hidden images aren't showing.
Basically I'm trying to imitate the bounce scrolling feature of the iphone UIScrollView.
I have my ScrollView all setup and I do a scroll at the beginning so as to hide the top hidden image. Now all I need to do is detect when a scrolling has ended, figure out the Y position, and check whether a hidden image is shown. If it is, I would just programmatically scroll the view back so that the hidden image is hidden.
I hope all that made sense.
So anyways, I know how to programmatically scroll a ScrollView. Now what I need is some sort of callback to tell me when a ScrollView ended scrolling and also a way to get the ScrollView's current 'Y' position. Are there any such methods I could use?
I looked through the ScrollView docs but nothing jumped out at me. I'm still not very familiar with the Android naming schemes so maybe I missed something obvious somewhere.
Anyways, any help would be appreciated here. Cheers.
You can use an OnTouchListener to detect when the user presses/releases the list.
You can also use the onScrollStateChanged method of the OnScrollListener class (most likely in conjunction with a touch listener) to detect changes in the SCROLL_STATE - when the list has stopped scrolling the state will change from a state that is not SCROLL_STATE_IDLE to SCROLL_STATE_IDLE.
Alternatively if you are using 2.3 or above you can use an OverScroller to get the desired effect (see Modifying Android OverScroll for how to change the over scroll effect to an iPhone like one).