Adding resistance/inertia/dead zone to scrolling in Android - android

I'm trying to implement a UI with a scrollable component that has a certain resistance to starting the scroll - ie. that you have to drag it a certain number of pixels before the scroll starts. Is this supported in Android, and if not is it something that can be added? The idea is to allow a scrolling component to snap to certain positions and resist being moved from them accidentally.

Yes, but you'll have to listen to motion events and track what's happening yourself.

Related

How can I make recyclerview scroll by only one direction and disable others

I just want to allow only scroll left in horizontal recyclerview for example. Please help me on that
Best way is to remove other directions item from adapter, which are getting hidden one by one. So when user scroll back ward it will not show up any thing.
I would not touch the data in your adapter (what does the data have to do with a UI business rule?). If you want, you could notify your Repository or ViewModel what views have been "scrolled" but that's a lot of events going up, and state coming down for everyone involved.
You have the tools at your disposal in the form of a combination of:
A GestureDetector (See (the documentation.)
A TouchListener (See (the documentation.)
Your favorite search engine to put these things together.
or perhaps benefit from the somewhat modular approach of RecyclerView:
Using OnItemTouchListener and a OnScrollListener to analyze the events and ignore the ones you don't want.
You could also create your own extended RecyclerView but that's more painful because you now need to change it all over the place you want this behavior.
In any case, your search engine of choice is also a good starting point. But think of this as:
You will need to intercept the touches and flings gestures (as well as other motion actions like "Dpads" and other Accessibility Events that may trigger a "scroll", evaluate in which direction this is headed, and determine if you still want that event to happen.

How do I cause vertical two-finger swipe behavior to cause a horizontal slider to move left or right?

I have a horizontal slider in my app, and I want to make it so that if you have the slider selected, you can do the two-fingered swipe up or down gesture from anywhere on the screen (The scroll up or down gesture) to move the slider left or right. I haven't been able to find anything through google about how to change vertical swipe behavior for Talkback and was wondering if there was in fact a way to change this.
I'd really suggest not doing this, it isn't how Android works so it will confuse your users, and be a big source of bugs as any behavior like this can cause touch errors on completely separate views. I just fixed a problem on something similar in my company's app.
But if you really want to do this- your root ViewGroup needs to intercept touch events if there are two fingers down and it moves far enough to qualify. Read https://developer.android.com/training/gestures/viewgroup#intercept for an explanation of how a parent view group can steal touch events from the child. This is the same way ScrollView works to scroll its contents. In fact, looking up the AOSP implementation of ScrollView would give you good example code.

Differentiate between manual and auto scroll in Android RecyclerView

This might be a basic question but I have a situation where I've setup auto scrolling of recyclerview (Combination of Looping through data objects, view holders and applying scroll to position).
The oversight I made was about how to handle the situation when user tries to regain control over the scroll ?
The problem: How to differentiate between user trying to gain back control (with manual scrolling) vs my loop trying to scroll through ?
Solution already tried: Use custom layout manager, override calculatespeedperpixel and provide custom value. Now when the user tries to manually scroll, if the scroll speed doesn't match my custom value, we can assume it was the user who scrolled.
This was a hackish workaround and wasn't fool proof always
Set up the touch listener for the recyclerview and when it triggeres you pause scrolling and after some time trigger automatically.

Android move items with acceleration

I cant seem to find the answer to this, mainly because I don't know what it is called.
I am going to expand a few features in my app, currently users can touch and drag to move forward in a list of images. What I want is for the users to "swipe" there finger and then all of these images will move under acceleration and will slowly come to a stop.
Is this a gesture? If so is it the "Fling" gesture?
There are several ways to do so.
Use ListView
Use Gallery
Use ScrollView
Use HorizontalScrollView
Write your custom ViewGroup or View
For the last approach, you have to detect the Fling gesture as you said and handle all the scrolling animations involved.

Android: How to detect end of scroll

I need to implement HorizontalScrollView which is scrolled to predefined positions (similar to Home behaviour). It works with slow gestures, but does not work with neither flings nor arrow key press.
I hooked to View.onScrollChanged() and it is called when scrolling happened, but I can't determine when scrolling animation ends.
In theory there should be a way to say that fling movement is over. Is there such API?
I did not find a way to track scroll animation, but it's possible to move scroll logic from HorizontalScrollView class to derived by you, where you can control every aspect of scrolling
I'm replying to a post a year old but this might be useful for future readers.
For implementing HOME-Like scroll, use Gallery instead of HorizontalScrollView.
Using 'Gallery' you need not worry about stopping scrolling at predefined positions and it gives you a handler for Fling-gesture too.
Add your code in onFling() or onScroll() as per your requirement.
More info # http://developer.android.com/reference/android/widget/Gallery.html

Categories

Resources