Android RotateAnimation overlapping - android

working in android last couple of days and i am trying to rotate an arrow by pressing a button. Using RotateAnimation and:
setFillAfter(true);
arrow remains in last position as supposed to.
But when i press button again arrow yes starts to rotate from initial position, but there is also the "previous" arrow from the last call of animation which is finally overlapped by "new" arrow. So i guess i need to somehow reset/clear the setFillAfter but i can't find a way.
My code goes like this:
//Animation start
float Xaxis=0.835366f;
float Yaxis=0.676692f;
RotateAnimation rotateAnimation1 = new RotateAnimation(0, 180,
Animation.RELATIVE_TO_SELF, Xaxis,Animation.RELATIVE_TO_SELF, Yaxis);
rotateAnimation1.setInterpolator(new LinearInterpolator());
rotateAnimation1.setDuration(2500);
rotateAnimation1.setRepeatCount(0);
image.startAnimation(rotateAnimation1);
rotateAnimation1.setAnimationListener(this);
#Override
public void onAnimationEnd(Animation animation) {
animation.setFillAfter(true);
}
Any ideas would be usefull..
I have tried invalidate, clearAnimation to image, setting fillafter to false, reset on animation but still same.

It is fixed, emulator is configured with shared GPU and runs perfectly. Fast and without any remainings of previous animations.

Related

How to make a clickable and animated textview?

I need to implement a moving/scrolling textview that got a clickable span. I also need to make the animation look like those banner ads below the news that repeat and repeat endlessly. I used TranslateAnimation before for a tv app and able to have it work because what I get is the keyEvent and the the touch. I need to implement it now on a tablet app which doesn't have any external input source other than the touchscreen itself.
I tried to use TranslateAnimation again for the tablet app but it doesn't work. Upon searching about the different animation I could use, I've learned that TranslateAnimation just animates the look of the view and the the whole view itself. It doesn't move the clickable parts with the look so I looked for a different one.
Then I stumbled upon PropertyAnimator. It's what I clearly need for my problem. But there's also a drawback to it. It doesn't support repeating.
What I currently have is this code below.
lbl.animate();
lbl.animate().x(-lblWidth).y(0);
lbl.animate().setDuration(animDuration);
lbl.animate().setInterpolator(new LinearInterpolator());
lbl.animate().setListener(new Animator.AnimatorListener() {
#Override
public void onAnimationStart(Animator animation) {
}
#Override
public void onAnimationEnd(Animator animation) {
lbl.animate();
lbl.animate().x(lblWidth).y(0);
lbl.animate().setDuration(0);
lbl.animate().x(-lblWidth).y(0);
lbl.animate().setDuration(animDuration);
lbl.animate().setInterpolator(new LinearInterpolator());
lbl.animate().setListener(this);
}
#Override
public void onAnimationCancel(Animator animation) {
}
#Override
public void onAnimationRepeat(Animator animation) {
}
});
After the first run, the animation ends. It repeats because it prints my log but it's not showing on screen.
I was trying to make a repeating effect with that code. I was trying to recreate something like this code below.
transAnim = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_PARENT, 1.0f,
TranslateAnimation.RELATIVE_TO_SELF, -1.0f,
TranslateAnimation.ABSOLUTE, 0f,
TranslateAnimation.ABSOLUTE, 0f
);
transAnim.setRepeatCount(-1);
transAnim.setRepeatMode(Animation.RESTART);
transAnim.setInterpolator(new LinearInterpolator());
transAnim.setDuration(animDuration);
transAnim.setFillAfter(true);
What the code above does is from the right, outside the screen, I start an animation that goes to the left, outside the screen. Then, if the view's end reach the left, outside the screen, tell the animation to restart from the beginning.
I made it work now by adding a single short line of code above everything.
lbl.setX(screenWidth);
lbl.animate().x(-lblWidth).y(0);
lbl.animate().setDuration(animDuration);
lbl.animate().setInterpolator(new LinearInterpolator());
Then using those line of code again on the onAnimationEnd of the animate listener. Now I thought of another thing, can I pause this animation? Because I found a way to do it for TranslateAnimation. Is there a hack way to do it?
Try this I hope it work for you.
lbl.animate();
lbl.animate().x(-lblWidth).y(0);
lbl.animate().setDuration(animDuration);
lbl.animate().setInterpolator(new LinearInterpolator());
lbl.animate().setRepeatCount(Animation.INFINITE);

After translating a view, the area where you press to trigger a button press doesn't move. How do you move this area with the view?

I created a button and wanted it to move to the bottom of the screen after some event is triggered. So I made an TranslateAnimation object
private TranslateAnimation setupAnimation(float yOffset) {
TranslateAnimation animation = new TranslateAnimation(0, 0, 0, yOffset);
animation.setDuration(1000);
animation.setFillAfter(true);
animation.setInterpolator(new AccelerateDecelerateInterpolator());
return animation;
}
Then I pass in the TranslateAnimation object into the startAnimation() method of the view I wanted to move.
Well that works for what I want to accomplish visually, but I noticed that I can't click on where it is visibly, but I can press where the button used to be and the onClick callback will be executed.
What do I need to do, post translation, to allow the user to press the button at its new location?
A TranslateAnimation only moves the pixels on the screen, it does not change the actual position of your Button, it just looks like it is moving, so your OnClick/OnTouchListener will not animate with it.
Use ObjectAnimator or ViewPropertyAnimator to really change the property of your Button.
Here is an example using ViewPropertyAnimator to get you started :
yourButton.animate()
.translationY(yOffset)
.setInterpolator(new AccelerateDecelerateInterpolator())
.setDuration(1000);
check the Docs for other available methods.

How do they do this? animated drawer rotation possible?

How do they do this? animated drawer rotation possible?
In the screenshots below, touching the 'Touch' circle at the bottom causes that circle to rotate around itself, and then 4 new navigation buttons come out that take me to other screens/activities in the app. I really want to have this in my app..
Is it a sliding drawer or some other strategy? BTW I am targeting android version 2.1
It looks as if it's mainly a animation that rotates an image. Once the animation has finished, the buttons are activated.
ImageView discsAndButtons = (ImageView) findViewById(R.id.discsAndButtons);
Animation anim = new RotateAnimation(0.0f, 90.0f, 0.0f, 480.0f);
anim.setDuration(600);
anim.setFillAfter(true);
anim.setAnimationListener(this);
discsAndButtons.setAnimation(anim);
...
void onAnimationEnd(Animation animation) {
ViewGroup buttonLayer = (ViewGroup) findViewById(R.id.buttonLayer);
buttonLayer.setVisibility(View.VISIBLE);
}
Visually, the buttons are part of the image. But the effective buttons are probably on a separate layer above the image and only made visible after the animation has finished (except for the TOUCH button).

Android RotateAnimation - rotate arrow back and forth

In my application, I am rotating a clock hand to the desired amount of minutes. This works good with RotateAnimation. Now what I want to do is to return the hand back to the starting position (0 minutes).
For example:
I first rotate the hand like this:
final RotateAnimation anim = new RotateAnimation(0f, ammountDegress, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 1f);
anim.setFillAfter(true);
anim.setFillEnabled(true)
Then I would like to move the hand back to it's starting position, so that means I should be calling a RotateAnimation after the first animation ends.
The problem is that the pivots have changed, how I can I set the pivot position to the exact position as previous? So that the rotating point is again at the same position of the clock hand.
Edit To make it more clearer - I would like to have something like a fixed point pivot that doesn't change with the rotation, so I am always rotating the hand around the same point.
I hope you can understand what I mean.

Leaving an Android Animation at it's end state

I'm trying to do an animation that takes a button (with a custom background image and system text) and fades it out. That works fine, actually. The issue is after the animation it goes back to it's initial state. I want it to animate and stay that way.
Thanks!
AlphaAnimation anim = new AlphaAnimation(1, 0.2f);
anim.setDuration (5000);
textView.startAnimation (anim);
anim.setFillAfter(true);
That should work.
My answer is 'stolen' form android.View transparency

Categories

Resources