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).
Related
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.
http://www.piwai.info/chatheads-basics/
By following this good guide, I can make a chathead and also detect the touch event.
However, if I touch the chathead with first finger, and try to touch other area (outside) the chathead with second finger, the second touch is not possible.
(The area outside can be the home screen, or another app, activity)
Similarly, IF I first touch the outside, and try to use second finger to touch the chathead, it is not possible.
I tried the similar interaction with facebook messenger chathead and it is the same.
My question is: is it possible to support the second touch?
maybe using dispatch touch event? but afaik dispatch is only for activity.
the chathead uses service and window.
Any help would be deeply appreciated!
Yes its possible using the following workaround.
Have a transparent layout surrounding your chathead.
This
transparent layout will intercept the touch and you can do the necessary
handling.
You can then pass this touch event up the hierarchy/other apps by returning false from OnTouchEvent().
To let the other apps handle touch event,the transparent view can only be activated when the user is already touching your chathead.This way you cna make sure that the user is planning to do some gesture with your chathead.
This isn't possible using layouts manually added to the WindowManager as a system overlay when the underlying view is from a completely different hierarchy.
Once you start a touch event on the first view, all subsequent touch events will be sent to the same view heirarchy until ALL MotionEvents are finished (I.e ACTION_UP or ACTION_CANCEL has occurred).
Basically, once you are interacting with one view heirarchy, any outside touches are interpreted as touches outside the current heirarchy, and ignore any underlying view heirarchies which may or may not occupy the same screen position.
here is the example screen i'm looking for, Is that possible with View-Pager.
When i slide to that particular direction need to move another activity.
I don't see why you want to use ViewPager here.
You can have a parent FrameLayout with four Views, for example ImageViews. Then, you can:
Override the onTouchEvent() in the parent FrameLayout and detect which image was touched and act accordingly (to get an effect you may want to move your image together with the MotionEvent.ACTION_MOVE touch event until a certain threshold and then start a new Activity) - You can use this post: move a view on touch move as an example.
Do the same by using Gesture Detector.
I have two scrollviews side by side, I want the user to be able to drag list items back and forth from left to right scrollviews. However, I can't find a way to handle the touch events. I can't set a touch listener for each scrollview seperately as the drag gesture gets dropped when passing from one to another. I tried creating an absolute layout over the top of both, which works from the drag and drop perspective, but it stops me from being able to scroll the scrollviews. Is there a simple solution to this? can anyone help me out?
Generally, onTouchListener returns a boolean that indicates whether the touch has been handled. It's up to you to decide whether the touch was handled or not. When the user touches a View, Android will call it's touch listener. If the touch listener returns true, then it regards the touch as handled then moves on. If the touch listener returns false, then it will go up one to the parent view (in this case whatever your ScrollView is). Then the parent view's touch listener is called and must decide how to handle the touch. It will keep cascading up the parent views until a true is returned or until it reaches the end.
In your case, you may have to decide what the user has to do in order to drag & drop vs. scrolling. Perhaps the user must do a long press on an item before he/she can drag it or something.
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