Android CollapsingToolbarLayout custom snap scrollflag - android

I am trying to control the scrolling behaviour of snap scroll flag of collpasingtoolbarlayout . According to this tutorial link
SCROLL_FLAG_SNAP: Upon a scroll ending, if the view is only partially visible then it will be snapped and scrolled to it's closest edge. what I'm trying to achieve is to make the Snap Behaviour works in 1 Direction only from Bottom to Top . which means if that view is close from the top edge and the user is scrolling from the bottom it should work normally in this cause. otherwise, for ex if user scrolling from top to bottom it should do nothing.
Here is a gif of Santa application of Google which I'm trying to achieve the same behaviour .
Gif Link

Here's a link to a post that was made before the support for the snap scroll flag which includes code that recreates the same behavior. You might be able to modify this custom behavior to fit your needs.
In that code you will find the following section which you need to edit for your "close to top or bottom" logic:
if (topOffset < -(scrollRange / 2f)) { //Close to top
// Snap up (to fully invisible)
animateOffsetTo(-scrollRange);
} else { //Close to bottom
// Snap down (to fully visible)
animateOffsetTo(0);
}
You will also need to include logic to compare the offset at the start of the scroll to the offset at the stop of teh scroll to determine the swipe direction.
Good luck!

Related

RecyclerView peek behaviour

I'm using a horizontal RecyclerView with PagerSnapHelper to make it look like a ViewPager. It's displaying child views.
How can I make it show a small peek of the next entry? The user needs to see close to 20% of the next entry to understand intuitively that they need to swipe horizontally. The earlier entry needs to align back.
There could be other indications of dots at the bottom but this is the expected behaviour. The child view occupies the entire recycler view, so adjusting the width of the child so as to make other siblings come onto the screen isn't an option.
Right now I'm using a RecyclerView that is set up with a PagerSnapHelper.
I'm able to scroll to 20% of the next entry by using this:
val nextPosition = (currentPosition + 1) % numOfEntries
val xscrollDistance = carouselRecyclerView.width * 0.80
linearLayoutManager.scrollToPositionWithOffset(nextPosition, xscrollDistance.toInt())
With this, I see the next entry come onto the screen like a peek but here's what I'm unhappy with:
This scroll isn't smooth, I'm looking for a smooth scroll to the 20% peek of the next entry
Snap doesn't work. I was hoping when I do step 1., the snap behaviour will kick in and align the earlier entry onto the screen. It doesn't happen that way.
The peeking behaviour also needs to be cyclic. Last entry's peek should be the 0th entry.
I'm also looking for a less complex solution if any.
I checked an older solution - How to peek RecyclerView + PagerSnapHelper but I'm hoping to find a cleaner solution instead.

Is it possible to customize the snap behavior of `ViewPager2`?

I need to emulate the behavior of Instagram's Reels which scrolls to the next or previous page when the current page is scrolled more than 50% upwards or downwards respectively and the finger goes up. ViewPager2's default behavior isn't satisfactory for this and I don't think I can change it without changing the PagerSnapHelper inside ViewPager2.
Is there any other way I can implement a custom Snap behavior for ViewPager2 then?

Fixed header with CoordinatorLayout showing shadow when scrolling

The classic coordinator layout gives you the following [source]:
However, I don't want the top header views to scroll until they "become" a toolbar pinned at the top, with a shadow below. I want them all fixed (or pinned) but to show the shadow only the nested scroll view starts to scroll under the pinned ones. Something like the main app drawer on Marshmallow devices, where the "search bar" becomes pinned and the list of apps scroll under it.
Hope I made myself clear. Is there any easy way I could achieve that without listening for scroll events and handling this manually?
EDIT
Here is what I'm trying to achieve:
. Notice on the right image how there is now a shadow below the list of apps because the user scrolled the list.
Thank you!
This is exactly what you are looking for: HideOnScroll
Set actionBar elevation to 0 initially. Add a scroll listener to your scrolling element. When you detect it has scrolled (dy > 0) you set the actionBar elevation to 4dp(the default actionBar elevation) and back to 0dp at dy == 0.
In your scroll listener you can, at least for recyclerViews, use the canScrollVertically function to check if you're at the top or not.

Android - swipe in/out view from/to the right screen edge

I'd like to implement a view that when invisible, slides in when swiping from the right (from outside of the screen). When visible, slides back out to the right when swiping to the right from outside that view.
So I guess this is called a swipe gesture while showing the slide animation as the swipe is still being done. I want it to be fluent, which means that if the swipe gesture is only part made, the view will only part slide, meaning the view follows the gesture.
I'm thinking of something very similar to Amazon's Cloud Drive months view. See screenshot below.
Any idea how to do this? An Example code? 3rd party library?
I tried to search for this. Found how to do the animation: here and here. Found how to recognize the gestures: here and here. Found even the combination of both but not when swiping from the edge of the screen to open nor when swiping from outside of the view to close.
Here are the things I investigated that didn't do the job and why:
SlidingMenu - Slides from the edge and from outside of the view but animates the main window and not just the side view. Also, it's very complicated and hard to get only the required behavior of sliding from/to the edge.
Roman Nurik's Android-SwipeToDismiss - Doesn't recognize swiping from outside of the view nor from the edge of the screen.
Wunderlists - Doesn't recognize swiping from outside of the view nor from the edge of the screen.

HorizontalScrollView Menu for Android

I have a menu that is made up of a HorizontalScrollView that has a LinearLayout with TextViews. When a user swipes/scrolls I want to be able to show and not show a leading and trailing image that represents that there are more options. So, when the application starts, the far left image is not shown but the far right image is. Once the user swipes to go right, the far left image is shown. When you get to the very last option to the right, the right image is gone.
I have tried to use the SimpleOnGestureListener but it seems that the position reported is where the user is instead of the position of the list. I was thinking I could just do something like:
if(scrollX < 200.0) {
tempL.setVisibility(View.INVISIBLE);
} else tempL.setVisibility(View.VISIBLE);
I even implemented both onFling and onScroll methods to try but did not get the expected results. Also, the position is only reported when the user scrolls again. So, a fling position may be 1278 and go all the way to 0 but 0 is not reported until the user tries to fling again.
Thanks.
You can use gallery for this. It has some limitations though, but I guess it would suit your requirement better than a horizontal Scroll View.

Categories

Resources