Drag and copy imageview to another view or framelayout - android

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.

Related

Child view move out from parent view and does not respond to pressing, Android

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.

Android Layout Transition Animation When Removing Then Adding The Same Child

Scenario:
I am creating a drag and drop feature within a linear layout. It is a very simple layout: one LinearLayout at the root and many Views within (for testing purposes they are just instances of the View class with different coloured backgrounds). I have created the system, you can 'pick-up' a View which is caused by a long click on one of the child views. This creates the drag shadow and at this point I call removeView() on the container to give the impression that the view has been picked up. I keep this view in memory. As the view is dragged around, a placeholder view is moved around to show the eventaul drop place for your drag location if you were to let go of the dragged shadow. This also works well and the removed view is then added back at the index where the placeholder was.
Problem:
When enabling 'android:animateLayoutChanges', the animations make this whole process look a whole lot smoother. The one artifact created by this is that when the dragged view is dropped (the same view that was removed when the drag started gets added back into the container) shows a transition animation from the dragged view's original position to it's new position. When adding a new view (for instance the placeholder gets created every time it changes position) it fades in instead.
Analysis:
From the looks of it, the container is remembering the view that was removed and so when the same view is added again, the animator interprets it as a move as opposed to a new view being added.
Question:
How can I prevent this behavior of the animator interpreting removing and adding the same child as a movement as opposed to separate remove and add operations?
Answer:
This is where you come in.
Thanks in advance.

New position of layout during animation is resetting after ui interaction

I am working in android 2.3 and I have an issue which is a bit of a pain.
I have 2 layouts on top of each other in a FrameLayout. The top layout is moved partly off-screen during an animation, and the .layout() method is called in the animation end. This works great and the ui is moved correctly and the buttons of the toplayout is still clickable.
After the animation the second layout is visible as the toplayout is moved off-screen. This layout contains a list which is clickable and each cell has an ImageView which is updated when clicked. However my problem is, when the table cell is clicked and the ImageView is updated, the entire view is reset, ignorering the animation and new location of the toplayout. It just sets the toplayout back on top as the animation never happend.
I use an TranslateAnimation and the set fillafter is set to true as well.
Do you guys have any suggestions to what I might be missing.
I guess your problem is placing objects inside FrameLayout. As described in this answer you cannot place a view inside a FrameLayout by setting its location.
It's true that with FrameLayout all children are pegged to the top
left of the screen, but you still have some control with setting their
padding. If you set different padding values to different children,
they will show up at different places in the FrameLayout.
Use padding instead to "move" the view off-screen.

OnTouchEvent stops firing when leaving parent, how change this behaviour?

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().

How to restrict bounds for Translate Animation for a view in Android?

Let me explain the scenario that I want to achieve:-
Consider the below as the Layout I have inside a Parent_Linearlayout:
[Linear Layout] (Fill_Parent, Wrap_Content)
[ScrollView]
Activity's setContentView is set to the Parent_Linearlayout
In the application, when a condition is met, I want the Scrollview to be removed from the screen and instead put another View in its place.
I've been able to do this, & when I remove the ScrollView, I'm applying translate Animation to it so that it seems as if the View has gone to the top -before removing it.
But when the animation occurs, the ScrollView translates OVER the Linear layout present above it.
How do I restrict it, so that the scrollview does not go over the linear layout, but disappears at the base of the Linearlayout. I want the linearlayout to always stay visible..
I've been trying to do this from quite some time, but I've not been able to get desired results..
Could someone kindly help me out here??
I don't quite understand your description of your layout, but the Android view system is drawn based on the ordering of the views in the hierarchy. Views added later to a parent are drawn after those added earlier. So if you always want the LinearLayout to be drawn on top of the ScrollView if/when they overlap, then declare or add the ScrollView object to its parent before the LinearLayout object.
In thinking more about this, I suppose the ordering here is important because you want the ScrollView to be placed below the LinearLayout in the parent of both of these views. Putting the ScrollView first (and thus having it painted first) would then put it above the other LinearLayout, which isn't what you want.
There are various ways to achieve what you want. For example, you could use a RelativeLayout as the parent of the views, then the ordering is not important.
Alternatively, you could place the ScrollView inside another LinearLayout (and that LinearLayout would be the second child of the overall parent layout). Then when you animate the ScrollView, it would be clipped by its immediate parent, which I believe would give you the effect you're looking for (make sure that setClipChildren() is set to true on this new intermediate LinearLayout, which it is by default, otherwise it won't clip the ScrollView as it animates out of it). Note that this approach would necessitate different animation values, since you are now animating the view outside of its parent (the new LinearLayout).

Categories

Resources