Overlapping views and drag events - android

I have two overlapping views which both consume the same drag event. Think a small circle under a much larger one. When the touch location cross over the smaller circle which is under (in zdepth) the larger one it triggers a ACTION_DRAG_EXITED event, even though the view's bounds have not been exited. The event is effectively hopping from the higher view to the lower view.
How can I prevent the lower view from triggering events when occluded?
thanks!
Nigel

In case anyone else encounters this, to fix it I used view.bringToFront() to ensure the larger circle view was on top. Interestingly even though it was drawing on top and its elevation was higher, android didn't consider it on top in the context of the drag event.

Related

Unclear MotionLayout parameters

Could anyone please explain what MotionLayout's onSwipe parameters touchAnchorId and touchAnchorSide do? This is what documentation says about touchAnchorId
View that is being moved by the swipe.
That doesn't make sense to me as swiping on MotionLayout doesn't move a single view. Swiping progresses transition between starting constraintSet and ending constraintSet. I thought initially that touchAnchorId would specify a view that user will have to drag to progress animation but this isn't a case and MotionLayout developer team introduced touchRegionId parameter for that. It's also unclear to me what touchAnchorSide is supposed to do as I don't see any difference when changing its value.
onSwipe Move progress from 0 to 1 along a
direction(dragDirection=) horizontal (dragRight/Left/StartEnd) or vertical (dragUp/Down)
If I drag my finger a 100 pixels along the screen how much does it move from 0 to 1?
That is the main question most of the other argument answer.
with out an anchor it uses the full length of the layout.
But if you are making a pull out draw that is excessive.
You could adjust it with dragScale. But how much? The pull may vary based on constraints fonts many things.
Many times you want it to act as if you are pulling a view or a side of a view. In which case you ned to the View (touchAnchorId) and the side of the view (touchAnchorSide)
Sometimes you want to limit the region in which the swipe will work
In which case you can use limitBoundsTo.
Much of the rest of the flags are bout what to do when you lift your finger.
There is much more subtly in all the use-cases it is designed to support.

Android - Increase Area of Drop Zone

I am following http://developer.android.com/guide/topics/ui/drag-drop.html and what I currently struggling with is, that I want to drag a relatively big view on a smaller button.
It seems ACTION_DRAG_ENTERED is only fired, if the touchpoint (center of the drag shadow) is within the bounds of the target view. However, I would like it to accept drops when the bounds of the shadow and the dropzone overlap. Is this possible?
(Note: I know, I could define a separate view as the drop zone and make it bigger than the actual drop-zone button, but that really complicates my layout, and I would rather work with the current view).

setClipChildren and hardware layers

I have a custom view group that I'm animating around on a screen based on touch events (drag and drop, for instance).
I want it to be able to draw slightly outside its bounds, and still animate smoothly.
I tried setting setLayerType(LAYER_TYPE_HARDWARE, null) on the dragging view, and performance was great, but anything outside the bounds was clipped.
I tried setting LAYER_TYPE_NONE, performance was still fine, but there was animation ghosting/streaking where the view had been dragged (as if it were smearing the screen).
Tried this on a Moto X and Nexus 4, same results.
What's the best way to approach this? Is setClipChildren(false) supposed to work with LAYER_TYPE_HARDWARE? Interestingly, LAYER_TYPE_SOFTWARE exhibits the same unexpected clipping as does LAYER_TYPE_HARDWARE.
Try to use following combination:
setClipChildren(false);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
android:hardwareAccelerated="false"
As described here: ViewPager and setClipChildren(false) workaround for 2.x devices
I had a similar problem when doing exactly the same thing. I wanted a drop shadow beneath my views. The problem is that the system will only clean up the rectangle left by the view you have moved and since you are rendering outside that view by choosing to not clip children, the rectangle is not covering all of your tracks and remains of the rendered view leave a smudgy sort of mess behind.
The solution I used was to put the view I wanted to move inside another view (A RelativeLayout with the child view aligned to the parent's center) that is slightly larger and does cover the drop shadow or whatever else you are rendering outside the bounds of your child. You can set the background of that parent view to transparent/clear. Now attach the drag action to your parent view and the Rect that is cleaned up behind it will also clean up the child's mess.
The only other way I found to do it which was very costly in terms of performance was to re-render the views that show the mess at each frame. I couldn't find any other solutions.

Android: How to make position of View match the visual representation after animation

I am currently trying to animate a card game using an AnimationSet of Translate and Rotate animations. Although I am using setFillAfter(true) and see the card visibly move and stay in it's new position, the actual position of the ImageView is still at it's old location.
In the Google documentation it says:
Note: Regardless of how your animation may move or resize, the bounds of the View that holds your animation will not automatically adjust to accommodate it. Even so, the animation will still be drawn beyond the bounds of its View and will not be clipped. However, clipping will occur if the animation exceeds the bounds of the parent View.
This means that all of my old onClickListeners, etc are still being associated with the old position rather than the newly updated visual representation, and any new animation applied to the View occur from the initial spot, not the newly located one.
What is the best way to get the effect that I seek (a card sliding from my hand to the center of the screen, which is a different LinearLayout, and then in a later sequence sliding from that spot off the screen)?
I know what I seek is possible as the people at bytesequencing.com have accomplished this smooth animation effect in their android game "Hearts! (free)" which I discovered in the market.
Thanks!

How to "scroll" a view of indeterminate size?

I have written a custom View which is used to display a tileable pattern, and want the user to be able to zoom in (which I've got covered) and then move around within the pattern.
Because the pattern is tileable it means that there are effectively no bounds on it. In theory a user could just keep scrolling left (right, up, or down) forever. In reality I would be using a modulus to adjust the virtual position.
I'm just not sure where to start. Would I use something with scrollbars? I'm not sure that makes any sense, because as I said the viewable area is effectively infinite.
Thanks for any suggestions!
I'd use a scrollview with the scrollbars turned off.
android:scrollbars="none"
I decided a scrollview was unnecessary. All I really had to do was handle the touch events and then adjust the virtual coordinates accordingly.

Categories

Resources