Start multiple ObjectAnimator animations on the same object one after another - android

I have a view in my app which I would like to animate while moving a finger on a surface view.
I don't want the view just to follow my finger but I would like to move it from its position to the new one with an animation.
For obtaining that result I intercept the movement of the finger on the surface view and start a new ObjectAnimator on the view to be animated, saying it to move to its new position. The problem is that, having all these ObjectAnimators which start on the same object in a so short time, the result is that I see the animation only when I stop to move the finger (seeing it moving to its final position).
How can I solve this problem?

Related

Viewproperty animation in Android works on horizontal movement not vertical

I have a 4X4 grid of textviews inside a constraintlayout. I also have an imageview that moves around the textviews upon touch input.
I override onGlobalLayout in order to record the tag id of each textview and its global location.
//inside onGlobalLayout
Rect rect = new Rect();
textviewMap.put(view.getTag().toString() , viewgetGlobalVisibleRect(rect));
So, the location of each textview is recorded in the map.
When user touches and moves the gamepiece I create a rect which computes if it intersects one of the rects inside the textviewMap!
I am able to detect the exact rect that it intersects and therefore move the gamepiece(imageview) to the centerX() and centerY() position of the rect that belongs to the textview.
Everything works wonderfully when moving horizontally. But vertically somehow the viewproperty animation does not work!
this is how I call the viewproperty animation:
if(direction.equals("horizontal")){ //works perfectly
gamepiece.animate().x(centerX()).setInterpolator(new
OverShootInterpolator).setDuration(600);
}
if(direction.equals("vertical")){ //not working good
gamepiece.animate().y(centerY()).setInterpolator(new
OverShootInterpolator).setDuration(600);
}
on the vertical movement the gamepiece jumps the textview below it and then if I try to move it up one textview it does not go. If I move two textviews vertically the gamepiece jumps only one textview NOT two.
The animations have a Animator.AnimatorListener and in the onAnimationEnd() I have tried calling:
gamepiece.clearAnimation();
animator.removeAllListeners();
Seems like this animation needs to be reset but on the vertical movement it does not work only in the horizontal movement!
see the picture I have attached!
Please help

How to draw an arrow instead of a dragshadow?

I need the user to drag an arrow between two views, but all info I can find online is to make a dragshadow.
here's an exemple of the result i need.
https://imgur.com/pfQxtSK
thanks in advance.
What you want requires you to observe touch events inside of your parent ViewGroup, or custom view (whatever is drawing the light-blue grid from the image), using onTouchEvent(MotionEvent) callback. Next, you wanna determine the direction of the drag using the MotionEvent's x and y coordinates and some basic trigonometry. This will allow you to determine the angle of the drag and therefore dynamically the adjust the angle (rotation) of your arrow so that it accurately tracks the finger. Next use the same x and y coordinates you got from the MotionEvent to determine where on the canvas to draw the arrow. If the arrow is another view added as a child, you can set that view's x and y coordinates or translate the view using methods provided by the View class (you may need to play with offset's so the view doesn't get drawn off-screen after several drags/touches). If the arrow is a bitmap our drawable, you will need to adjust the draw coordinates in your view's onDraw(Canvas) method.

Android finding X and Y in tween animation

i have a drawable frame animation and i also implement tween animation on it. In drawable animation my sprites it walking without moving its location. and through tween animation it is moving from x 1% to x 100%.
the code of both animation is as
Animation movement = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animationball);
anim.startAnimation(movement);
anim.setBackgroundResource(R.drawable.smurf);
AnimationDrawable walking = (AnimationDrawable) anim.getBackground();
walking.start();
it is working fine and my animation gives illusion that m sprite walking from left to right.
now i wanted to get X and Y location of this animated sprite at every pixel of its movement path.
i implements runnable on same activity class and the code of its run() method is as below
#SuppressLint("NewApi") #Override
public void run() {
tv.setText(""+ anim.getX());
}
then i start the thread in onCreate method as
Thread t = new Thread(this);
t.start();
in run() method tv is a TextView and i wanted to observe the locations through it. but it always showing 0.0
i am unable to understand it why it is not showing the x locations ?
With tween animation or AnimationDrawble and View Animation (Animation class), the animated view's "real" position is not changed even though the view is animated to a different location, for example, you can create a button and animate it to the right side of the screen, but when you click along on the button when it is moving, it will not get depressed, but if you press its initial position (even if the button is not there), the button will get depressed. If you want to also invalidate the view's position, use the new Property Animation, click HERE for more detail.

Get coordinates of imageview during animation android

I am trying make an animation of an imageView from left to right and get it back from right to left but I also want to get the position of the imageview while its animation from the following code. I want to use the coordinates from origin to display in my app. Please tell me how to do this. Following is the code I am using to animate and move position of imageview.
Animation anx = new TranslateAnimation(0,100,0, 0);
anx.setDuration(2000);
anx.setFillAfter(true);
myImage.startAnimation(anx);
Is there a function like getX() and getY() to get position.
Have u tried to set animation listener and starting a runnable when the animation starts to check the image getx , gety every milliseconds u want and stop it after the animation ends

Reversing view animation on Android?

So if I have a translation animation like
Animation anim = new TranslateAnimation(0, 0, 0, OFFSET);
anim.setDuration(1000L);
anim.setAnimationListener(listener);
anim.setFillAfter(true);
and I apply this to a textswitcher so that given a offset, the textswitcher will move from a location, A, up or down.
My textswitcher will stay at a given location, B, after the animation due to the setfillafter. How can I then from that location, B, reverse the animation and go back to location, A?
The Overall Question
So I'm translating a textswitcher down and then up, but of course, setfillafter only translates the bitmap of the view and not the view itself, so this may not be the best approach. I've also tried to do an animation and then offset of the view, but that looks glitchy. So basically, I want a view(textswitcher) which a swipe/fling down will move it down and touching(onClick) it when it's down will move it back up (same animation reversed). How can I do this?
I know how to do the swipe/fling and onClick stuff, just not how to implement the correct animation.
Perhaps you may want to consider adding an on touch listener to see where you touched it last, If above move up with a constant animation. This is if im understanding the question correctly.

Categories

Resources