When vertically sliding finger on a ListView, it starts to scroll after a small move.
Is there any way to increase this "gap", so it would be necessary a "larger" move to trigger the ListView's scrolling?
There's nothing explicit like setSensitivity but you might be able to set a flag to detect when the ListView isn't scrolling. So then onScroll if the flag is set to true, (meaning that it has started scrolling from a fixed position), set the flag to false, and in the override of the scroll method only allow it to scroll once the amount is over 10dip for example...
Then when it stops scrolling again, set the flag back to true.
It's just an abstract idea but it sounds like it could work.
Related
I am using two (embedded) ScrollViews like suggested here, in order to create a '2D Scrollview'.
I add multiple childs to this view, and to some of them I set OnClickListener (I also tried with OnLongClickListener as well).
Functionally the result is what I have expected, although if I try to scroll (starting from a child, that has either of the listeners), the scrollview jumps/repositions to the ~opposite direction, I started the scroll to. So if I scroll like this e.g. upwards, the view jumps a big downwards so that I can scroll up at most to the original position.
I have been trying to play around with calling setFocusable(false) on the childs and setFocusable(true) on the ScrollView(s) (but also tried different permutations of it, as I am not sure about setFocusable()), but couldn't really get on top of it.. Any suggestions?
Just encase you are still wondering this is happening because when you start scrolling the other scroll view, ACTION_CANCEL is posted to the on touch method of the original ScrollView which causes a default scroll view to jump back to its original position.
I need to do some animations in a listview after it is flinged and is about to stop.I have a listview which is going to be of a fixed height(well dont ask me why), and whenever the scroll stops , it should have three elements visible. What i do now is detect when the list reaches SCROLL_STATE_IDLE and if i have two elements visible at that time, i use smoothScrollToPosition and reach a state of 3 items visible and it works fine, but what i would like to do is detect when the scroll is about to stop and stop the scroll programatically when there are three items visible. Is that even possible... Any code snippets, pseudo code, algo would help me.
You can set an OnScrollListener, and then store the value from absListView.getScrollY() each sample and compare it the previous sample to compute the velocity of the scroll. Once that drops below a threshold you define, you can take over scrolling.
I have a layout which looks something like this:
Inside the ViewPager are a number of Fragments, of which each holds a ListView.
Now I want to do this:
By scrolling down, the ListView mustn't scroll. Instead the header has to be transformed so it looks like a native ActionBar.
I'm doing this by intercepting the TouchEvent in the root layout of my activity.
I have overwritten the onInterceptTouchEvent() method of my parent layout and check if a TouchEvent should be intercepted or not, by retrieving the current visible ListView and check if the firstVisibleItem is the first and it's completely visible.
If the TouchEvent should be intercepted, my custom OnGesutreListener's onScroll() method is called. So the "animation" progress depends on the scroll offset.
All that works really fine. But now here's my problem:
The transformation is ready and the user still scrolls down. As a user i would expect the ListView to scroll down. But the TouchEvent isn't dispatched to the ListView because it's still intercepted by the parent layout. Only after moving the finger up and down again onInterceptTouchEvent is called again (now the parent layout hasn't to intercept) and the list is scrollable.
I tried a few things but they didn't work out for me:
I tried to call my listView's onTouchEvent manually in the
onTouchEvent() method of my parent's layout - noting happens
I tried to call my listView's onTouchEvent manually in my onScroll method,
also this didn't worked out.
Maybe some of you have a clue how to work this out.
Thanks a lot and greetz!
Could you try getting the x position moved by the finger in the parent onTouchEvent and then using
listView.smoothScrollByOffset(int offset);
To scroll the list view?
Edit: Based on feedback it should be:
smoothScrollBy((int) distanceY, 1);
Thanks to MungoRae's answer I could figure it out (please give him an upvote!)
listView.smoothScrollBy(int offset, int durationInMillis)
this works fine for me. The offset is the scrolled distanceY and the duration is set to 1 msec
You can use View.requestDisallowInterceptTouchEvent(). It will enable and disable the ability of a view to intercept touch event.
set requestDisallowInterceptTouchEvent(true) on the parent layout while touching , it will enable the listview to handle the touch event.
It is possible auto scroll in android? I want my layout to start scrolling when my user loads up the screen, is it possible to do without them having to touch the screen?
I don't think, there is a default method to solve this. However the ScrollView class (you probably need a ScrollView, to make the content scrollable) has a method, which enables you to scroll smooth through the content:
smoothScrollBy(int,int)
the first (x) value is the horizontal, and the second (y) value is the vertical scroll. You could use a background Thread to call this method with the desired parameters, until the end of your ScrollView is reached.
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).