Android "hover" event in custom layout - android

I have a custom layout that I have written that basically just displays a bunch of ImageViews. I am handing onTouch events for all the ImageViews in my layout.
However, if a user touches one imageView and then drags over another ImageView, I would like to be able to handle that as well.
How would I go about capturing this behaviour?

maybe this example is useful: http://www.anddev.org/viewtopic.php?p=11603
it relies on tracking the event with MotionEvent.ACTION_MOVE. the coordinates could be checked to determine when the element enters/exits a cell.
it uses drawview, but hopefully the same can be done w/imageview

Related

Android : How to detect onTouch event on a view, with touch down outside the view?

In an Android fragment, I have a GridLayout with views in it.
I would like to be able to detect when a user swipes over a view, even if he initially touches down outside of it. I've included a diagram to illustrate what I mean here :
Is there a simple way to do this (without using coordinates to see if the touch point is in the view)?
Thanks!
You solve this using View.OnTouchListeners.
Set OnTouchListeners both root view as well as your view.
Check for Events and actions ACTION_DOWN(touch event start),ACTION_UP(touch event over)
Set flags as per need for inside touch or outside touch.
basically you need capture events as well as points too.

Android parent onTouchEvent hijacking child onTouchEvent

I have an android application screen in which I have a form where user can take image and fill details about the pic. I also want user to write something over the image (its like drawing with your finger), but the problem is that too many fields have made the view scrollable and therefore user is not able to draw over the image. Can I somehow disable the parent scrolling when I am touching my imageView?
Have you tried with :
mYourImageView.requestDisallowInterceptTouchEvent(true);
Called when a child does not want this parent and its ancestors to intercept touch events with onInterceptTouchEvent(MotionEvent).

How to enable dragging multiple ImageViews?

After I have added multiple ImageViews to a LinearLayout and implementing the onTouch event, the touch is enabled only for the last added ImageView and all the previous ImageViews don'. What is the possible solution ?
I have tried the code from the android developer blog:
http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
Multi-touch in that example is designed for multi-touching a single View, not for touching multiple views at the same time.
This might help: Android firing onTouch event for multiple ImageViews
The solution you might be looking for, if you want to give the effect of multi-touching ImageViews, is placing another view on top of those views which allows you to capture all the touch events and pass the appropriate action to the view below it.
In my experience it has been much easier to use a SurfaceView and render the images to the view myself but this wouldn't be appropriate if there are other behaviours of View which you want to take advantage of.
Android Launcher app supports moveable views using the touch interface. The Launcher object model includes objects like DragLayer, DragSource, DragController, and DropTarget.
Using this concepts there is a nice tutorial for Moving Views In Android.
Look at that, I think its what you needed.

How can I drag a imagebutton in android

I'm using ImageButton's in my application. By using onTouch event and onTouchListener I'm responding to the touch events.
Once the touch event was completed I'm just displaying the ImageButton at target location.
Instead I wanted it to look like dragging of ImageButton. Can anyone point me in the right direction.
This blog has two very nice examples of how you can use touch events to move any kind of view around the screen.
I'm not sure I understand what the problem is. You wrote "Once the touch event was completed [...]" - does that mean you've got it to work in one situation but not others? Are you considering that the touch event is completed when the action of the MotionEvent is MotionEvent.ACTION_UP? If you've got that part working, then why not just re-use that same code for the action MotionEvent.ACTION_MOVE?
Define a own view wich is extending imagebutton, define a drawable for "active" state and set (or reset) the drawable onclick

ViewFlipper caching issue

The views are not cached in a ViewFlipper. Is there a way wherein we can get an image of the view and show it to user so that he sees the Ui as we see on Home scrren(when we swipe the previous view also moves along and when we lift our finger, only then the next view is shown completely.)
What I want to do is that when the user starts moving his finegr on screen, the view should also move along(create an image of view).
I am not getting to do this, as when we swipe the present view goes and next view comes, we do not get both visible when we r moving our finger on screen.
Please if anyone gets what I am trying to do, do help me.
Thanks,
Farha
It's tricky to get scroll and swipe tracking working on Android, while using ViewAnimator or its subclasses.
They allow you to set in and out animations and start them at a given moment, but they work with discrete, either-this-or-the-other-view animations. They are actually using FrameLayout and after in or out animation is executed, other views' visibility is set to View.GONE to hide them from showing up under/over your current View.
The Launcher and the Gallery application are actually doing the functionality you want, by using a different approach.
They track the user touch input (onTouchEvent()), on MotionEvent.ACTION_MOVE they perform animations manually and on MotionEvent.ACTION_UP snap to the appropriate view, just like in the iPhone.
Unfortunately, this approach is actually more complicated than it looks like.
With the manual handling, you have to ensure that you are taking care of everything related to the touch input. This includes a lot of flag-raising, value-checking, event-delegating, etc.
If you want to get better acquainted with this, take a look at these classes from Gallery3D or Launcher's source code.
One other way to get nice horizontal scrolling is to use HorizontalScrollView.
You have to figure out a way to recycle your views, like you would with a ListView and you have to add the snap-to-view logic, but if you have to take care of a small number of views it could be the easiest approach.
Hope that helps.

Categories

Resources