GridView eats my onTouch events and starts "scrolling" - android

I am creating an android app in which I need to track the pointer on a couple of elements that are inside a GridView. The problem is that if the pointer moves a little bit up or down, the GridView enters some kind of scrolling mode (even if it fits easily inside the screen), so the events do not reach the child views anymore. Is there anything I can do to prevent this behaviour and keep tracking the pointer inside those children?
So to clarify: the pointer tracking works neatly, until the vertical difference between starting and current position becomes to large. At that moment, no touch event reaches my child elements anymore, and the gridView starts scrolling if it does not fit inside the screen.

I found a solution at another StackOverflow post. Simply put, the solution is to create a class that extends the GridView and overrides the onInterceptTouchEvent method, which must return false when scrolling (or any other form of interception) has to be prohibited.

Related

android drag and drop gridview ordering

I created a drag and drop gridview (using an OnDragListener). Grid items can be dropped upon one another. However, I also want to be able to re-order them. I implemented this, but there is a major issue left standing: the user control part.
When I drag around my shadow object I want the items to make space for my dragged object while I am dragging it around. I already implemented the moving of the other items, but I cannot seem to figure out a way to find out IF/WHEN I am in between two items. I get drag events when I hoover ABOVE an item, but not in between then. The gridview does not get any onTouchEvent calls when I am dragging, not even onInterceptTouchEvent calls.
Does anyone know a way in which I can implement this?
I already tried:
Implementing onTouchEvent and onInterceptTouchEvent in the gridview. Problem:
The gridview does not get any onTouchEvent calls when I am dragging an item, not even onInterceptTouchEvent calls.
Setting another draglistener on the whole gridview. Problem: ACTION_DRAG_LOCATION gets only called a few times, not on every move (location change), as is documented (!!).
I removed the padding between the grid items and gave the items themselfes some extra size, so that you are never inbetween items, but also on the side of one of the items. I detect when I'm at the side of an item and move the items accordingly to make space for my dragged item.

DirectionalViewPager with 30 buttons in every page

I am trying to use DirectionalViewPager for displaying 30 buttons in every page. Normally this viewpager is working perfectly. But, if I try this pager after adding buttons then the touch is not sensible or smoother. I observe lag and irregular touch sense when there are some clickable items on the fragment.
When I try dragging the pages by dragging using non-clickable items, then its working perfectly.
Can any one assist me to handle this issue?
This issue occurred due to the Child buttons in the gridview. Because If we override onTouch method for the Button then the X and Y points are given with respect to that particular button only. So if you are passing these values to the parent then you should change the values according to the parent or else you can directly pass the Button's X,Y points which will improve the Touch sensitivity more.

android gallery scroll in between items

In my application I have a custom gallery which shows some LinearLayouts (custom components to be precise, but that doesn't matter I think).
What I want is that if I scroll in between to items that it stays there and doesn't select the closest one (as it does by default).
If I override the onTouchEvent and in the case of an ACTION_UP ignore the event I get the desired result, BUT then I lose the onFling (the scrolling doesn't continue but stops immediately).
Then I think I'll have problems with my indicator of the position as I will probably lose the OnItemSelected handle, but I'm not sure of that (of course).
every suggestion is welcome.

One touch event puts all child views into pressed state

Doubtless this is caused by my decidedly unorthodox layout - I have buttons in a LinearLayout in an Activity which is placed by an ActivityGroup into a Gallery. The ActivityGroup is also the adapter implementation and the over-all effect is full-screen sliding, snapping panels.
This is working (a treat, actually) except that a touch event on the parent layout puts all the buttons into the pressed state (and any release removes the state). A touch on an individual button is only delivered to that button.
The buttons are not receiving any events, they're only changing state.
Have I done something obviously wrong? Is this a known bug and is there a work-around?
Any insights would be very much appreciated.
As obscure as this problem is its solution may be of use to someone else, so I'll answer my own question.
As mentioned, I'm (mis)using the Gallery to provide a slidey-panel à la iPhone. I do this by returning the top level window of an Activity when the Gallery asks its Adapter implementation for a view.
Typical use of a Gallery would result in small Views to which it's desirable for the press event to be applied - it's more like a button then it is a panel. Our use means that there are many buttons in a single view and we don't want the press event to ever be applied globally.
So the work-around was very easy. I extended Gallery and deliberately broke pointToPosition(int x, int y), returning INVALID_POSITION every time. The Gallery still does everything else expected of it but skips trying to apply the touch down event to any elements but itself (to prepare itself to scroll or fling).
I hope this is of value to someone.

Android: Detect when ScrollView has finished scrolling and bouncing back?

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).

Categories

Resources