I want to implement drag-and-drop in an android application to switch a child view from one custom view to another custom view (of the same type).
My problem is that the OnTouchEvent stops firing when leaving the direct parent while draging (in my case the custom view is build like this: RelativeLayout -> (TextView, Button, LinearLayout -> (*LinearLayouts containing *ImageViews)). I want to show a list of images wrapped in more rows if the images doesn't fit in one row...)
In fact i want to drag one of those imageviews (parent is a linearlayout-row, where the parent is a linearlayout where parent is a relativelayout) to another custom view of the same type. (it just has to be droped over the other view and be added to the other list...) but it always stops receiving the events when leaving its parent linear-layout.
Can you help me understand how the OnTouchEvent is handled when nested in different views? (already tried to add the OnTouchListener to every view and even the rootview of the activity)
To continue to receive touch events outside of your View, call getParent().requestDisallowInterceptTouchEvent(true) from onTouchEvent().
Related
Saying that I have the following view:
<FrameLayout>
<View />
</FrameLayout>
There are something that I need to achieve:
Detect move event on FrameLayout, which is MotionEvent.ACTION_MOVE. This can be achieved easily by implement OnTouchEvent. But the problem is coming from the child View
I would like to implement onClick event on the child View, therefore I have to consume the event in the OnTouchEvent of the child View. The problem is when I return true (consumed) on the child View. The FrameLayout (parent view) won't be able to receive any further events (only MotionEvent.ACTION_DOWN can be received)
So the question is how can I able to dispatch further events to parent view? In Android, view like ScrollView are able to achieve that. How can we achieve same thing as ScrollView? (Still able to dispatch event further down but still able to capture the gesture to scroll)
This is just an example. The real code have multiple nested view inside
I have a RecyclerView (which scrolls vertically) whose ViewHolders contain RecyclerViews that scroll horizontally. When you tap on an item in horizontal (nested) RecyclerViews, I want the entire row to have the ripple effect.
To do this, I've been trying to override the touch events and get them to get passed up the view stack (by returning false in touch event handlers). This works on views other than RecyclerViews, but it isn't having the desired effect for RecyclerViews.
How do I correctly pass the tap event on a RecyclerView up to the enclosing view?
Haven't found a way to pass the click event up to a recycler view's parent view, but the important thing was getting the ripple effect to happen – which I was able to do. So when a view holder's itemView get's tapped, I do this:
val background = itemView.background
if (background is RippleDrawable) {
background.setState(intArrayOf(android.R.attr.state_pressed, android.R.attr.state_enabled))
}
Which manually triggers the ripple effect.
Trying to create an application where a user drags a view (button/imageView) from a parent layout on top of another layout (probably a framelayout) in a single activity and have it stick to where i dragged it (kind of like a sticker).
The user could repeat this process until the framelayout is filled.
Currently looking at handling onDrag events and on ActionDrop just add a copy of the view being dragged to the new container. Kind of like this except without the removeView method.
Is there a better way? How would i do it if i wanted to place the view being dragged exactly on the same position ontop of the framelayout.
After animation button moves out from parent layout and does not respond to touch. I tried to use TouchDelegate for extending a view's touchable area, but it did not work in my case. I need it to scale (parent layout with all childs), and I do not want to change the size parent layout. Whether it is possible to solve this problem?
thear scheme of problem
I use TouchDelegate for Parent view and check window location coordinate for child views. When there is a pressing on the ParetView, I check to see if in the same place a childView, and if so, then move it.
I have a custom ViewGroup and would like to add scrolling ability to it.
Is it possible to use a Scroller object and link it up with view group?
I have read somewhere that Scroller does not do any actual scrolling. That means it must be delegating the scrolling responsibility back to ViewGroup.
thanks
The ScrollView object is what allows for scrolling. Basically, most Views are able to be scrolled, but they have no way of propagating touch events to the View class. A ScrollView handles this for the user, so should be wrapped around a View whenever you would like to enable Scrolling for a that view.
Remember that a ScrollView can only have one child view, so if you need have multiple views in the same scrolling layout, you'll need to have them all inside one LinearLayout (or RelativeLayout, or whatever you decide).