I am using a CustomSlider in my app, and I have set it to be invisible.
When the user drags it or touches it (from top to bottom), my application needs to make the slider visible. Is this possible? How would I achieve it?
I needed to do this with an ImageView and still get touch events. The solution was to setAlpha(0.0f) to hide the image and still get events.
The touch event will be detected on the visible Views of your activity. While a View instance is hidden / invisible, you cannot interact with it.
You need a motion handler on the parent view / visible view to determine whether you need to show the slider (in case the motion is vertical) or not.
Related
I want to perform an action when user turned off or on by dragging the view and I don't want it to stop in middle.
Any Idea how to achieve this?
to perform dragging, you have to use motion layout for it, Click here for more reference.
I have a ListView with video items. When user clicks the image of the Video it goes to a new screen and starts playing the video. If user clicks a button next to the video image then I display a BottomSheet from google design library. Because I want to apply a shadow when bottomSheet is expanded I have a View with a transparent dark overlay just above the ListView, which initially has visibility set to Gone and I change it to Visible when I expand BottomSheet.
The problem is that despite the shadow layer items below it can still get click events which is a behavior I want to prevent. Is there a solution for this ? Maybe an attribute for that view so when its visible won't let touch events happen ?
Hey if you want to disable the touch intercept capability of view by you self. If it is a button or Views like Linearlayout, RelativeLayout just use view.setClickable(false) once you hide the view. Otherwise views intecept touch events even ,if they are not visible(Given that none other views are intercepting touch event for that portion of screen).
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.
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).
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.