Android actions during animation listener - android

I have an image I can drag on the screen thanks to an OnTouchListener.
While moving this image I draw a thin line that "binds" it to its original position.
Now when I release/drop the image, I have a TranslateAnimation which makes the image go back to its position or out of the screen, depending on the dropping area.
How could I redraw the line during the TranslateAnimation so that the image is still bound to its original position while moving?
In AnimationListener there's onAnimationStart, onAnimationRepeat and onAnimationStop, but I see no trace of a onAnimationProgress or so.
Is there a way to get the changing position of a view while animating? Other than an infinite loop on the view position and an if to check if its position changed...

I think you can achieve what you want by creating your own Interpolator for the animation and then whatever you want when getInterpolation() is called.

Related

Rotation of a view in a ListView's cell

I will try to explain.
I have a ListView with its adapter which defines the method getView (as usual) for retrieving the appearance of the cells. The final appearance of the ListView is the one shown.
As you can see the first arrow is rotated of 180 degrees. It has been rotated with an animation once I clicked on it. If I'd click on it again it would be rotated to the original position again. The rotation of 180 degrees is maintained with the fillAfter parameter of the animation (then it is not fixed definitively once the animation completed).
The problem is the following: when list view is scrolled and the cell with the rotated arrow is brought out and in again the cell's view is loaded again. At this point I need to rotate the arrow again. I have two ways:
use arrow.setRotation(180f)
use the same animation used before with the duration set to 0
Both the ways have a problem:
The rotation is fixed, then when I call the method for rotating the arrow to its original position the arrow is ALREADY on its original position (because of setRotation)
The rotation is not immediate, then, when the cell is brought out and in again, for an instant it points right and after a moment left
How can I solve this problem?
I need to rotate the arrow before of bringing it in again but without fixing its state as rotated of 180 degrees.
I will suggest you if you have less posibilites of items to be placed in listview then use Dynamic Linearlayouts in ScrollView instead of ListView. As ListView generates many complexities in its own layout In making custom adapter like putting edittext in listview and do some action like delete/animation on UI component of yout listItem.

ImageButton animation

I am implementing a animated book in Android and the animations are defined by an XML (not an Android XML). The images are positioned in fixed positions and when user touches in a element on the screen, the app plays a sound and animate the imagebutton, changing the image src and positions (X and Y).
I want to know how can I do that. As images dot not have the same size, I think the sprites solution is not a good way to solve it.
Its like the image 2:
Thank you
There are two types of animations:
View Animation and Proprety Animation.
The view animation can only animate View objects. It also lack a variety of animations, since it can do only stuff as scale, rotate, move... It cannot change background color, for example. Also, the dissadvantage of the View Animation is that it only change the position of where the View object is DRAWN. Phisically, it still stays in the same position. That's why the button is unclickable, after the View Animation is finished upon it.
Property Animation, in the other hand, can animate both View and non-View objects and it doesn't have constraints as the View Animation. When objects are moved, for example, with the property animation, they are not just drawn on some other position on the screen, but they are actually MOVED there.
Now, Property Animation is a lot more complex to write than the View Animation, so if you don't really need all the advantages of the Property Animation, it is suggested to use View Animation.
Source: Property vs ViewAnimation
Tutorial and SupportLybrary up to API 1: Nine Old Androids

Android: My imageview is rotated, but its touch area isn't

I have a rectangular Imageview that responds to touch (it rotates by a specific number of degrees, using animation). The imageview has an ontouchlistener attached to it.
However, once it has rotated, it still responds to touch only at its original (pre-rotation) location. Even though I have setfillafter to true.
My theory is that the rotation is for display purposes only... is there a way to detect a touch on a rectangular imageview rotated at an angle - e.g. 45 degrees?
When animation is applied to a view in android, only the pixels of the view are shifted while the hit area remains in the same position.
To actually move a view, you will need to add a animation listener to the view and manually change the view position on animation end.

How to animate Bitmap on Surface view onDraw()?

I am trying to make a game. I try to use GridView but wonder how can I drag Item onTouchEvent(). I found an example
http://www.droidnova.com/playing-with-graphics-in-android-part-ii,160.html
It is a great example. I cropped my image in 12 small image bitmap. display them on screen randomly on specific position.
By overriding the onTouchEvent() I got my requirement. Now I want to animate my image as the "swap" other image by animating. I have both images X,Y location.
I am wondring if it can by done by some Animation class.So that I should not put effort for doing it manually. I know it is not a hard job. But I Animation class can do it more smoothly.
So I have a ArrayOfImages(Bitmap) and I want to swap 2Images with animation. I am using a thread that update "Canvas" in background. Please help me.
.
I more thing. How can I add Scroll view with surface holder?? Is it possible? Because I think when I try to drag my image , It my not drag and active scrollbar for this response?
Finally I am using a loop for a specific x,y to a specific x,y while updating the canvas. Although this is not a efficient way.

Android: Animating View position

I'm trying to do something which seems simple. I want to have a map view, with a menu that slides up from the bottom of the screen where settings (for overlay) can be adjusted. However when I use a TranslateAnimation to affect the y position of the LinearLayout (which holds the menu), the buttons in the LinearLayout move, but there "hit area" stays in the same position as they were before the animation.
TranslateAnimation slide = new TranslateAnimation(0,0,0,0);
slide.setDuration(300);
slide.setFillAfter(true);
pullupMenu.startAnimation(slide);
mapContainer.startAnimation(slide);
I've also looked into tweening the view's marginTop value, but haven't even been able to determine how that would be done.
Any help on either of these directions would be much appreciated.
The animation in general is animating the pixels of the widget. My suspicion, based on what you wrote, is that setFillAfter() merely arranges for the pixels to stay in the destination location, not the widget itself.
If you want the animation to actually wind up moving the widget, you need to:
Register a listener to find out when the animation ends, and
Arrange at that point to modify the layout rules such that the widget actually exists in the new location
You can see a sliding pane that employs this technique here.

Categories

Resources