Rotation of image using ViewAnimation or PropertyAnimation in android - android

I want to rotate an image in my application in such a manner that it rotate like a simple pendulam and will stop after some time.
How I can achieve it using View Animation or Property Animation in android
I used the below xml for the animation
<rotate
android:duration="2000"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="-15"
android:pivotX="50%"
android:pivotY="0%"
android:repeatCount="5"
android:repeatMode="reverse"
android:toDegrees="15" />
And below is the code for the animation
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this,
R.anim.rotate);
firstBell.startAnimation(hyperspaceJumpAnimation);
But the problem is when animation starts it suddenly move to angle -15 and then start animating. And it stops after 5 count suddenly not in smooth way.
So my question is how to resolve this issue
Looking for help.

About -15 degree:
android:fromDegrees="-15"
and
android:toDegrees="15"
These two lines mean your object start from -15 degrees and end with 15 degree. If that are not what you want, just delete them.
For the Smooth way, you may find the fade.xml in your ApiDemo/res/anim folder.

Related

Android animation rotate infinite, without pausing

I can rotate my image infinitely. But my problem is that the image pauses shortly when it reaches 360ยบ and then starts rotating again. It happens the same even when I applied "linear_interpolator".
What I want to do is that the image does not pause at all when it starts the next round. So it has to rotate infinitely with same speed at any degree.
Here is my - code. Thanks
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="#android:anim/linear_interpolator"
android:duration="1400"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="360"
android:repeatMode="restart"
android:repeatCount="infinite" />
</set>
How I call it on my code
rotate= AnimationUtils.loadAnimation(context, R.anim.loop_rotate)
binding.imgSecondLayout.startAnimation(rotate)
Thanks for help! :)
Add animation.setRepeatCount(Animation.INFINITE) to your java class where animation is called.
My final code is given here:
Animation animation = AnimationUtils.loadAnimation(getBaseContext(), R.anim.loop_rotate);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE);
animation.setDuration(1400);
youractivity.startAnimation(animation);
This is due to the small delay after the animation completes its duration (1400 ms in ur case). you can remove this delay for smooth animation.
Remove repeatMode attribute and instead add this line :
android:startOffset="0" //Delay in milliseconds before the animation runs
The animation will be smooth without any delays

How do I animate, Moving an ImageView on a circular path with certain radius in android?

Please Find the attachment for my image.
https://docs.google.com/file/d/0B_c-SDSO63obS0ZyQ1dsOXdUQmc/edit?usp=sharing
My task is, animate that GONG type of image up to some time with clock wise and anti clock wise.
For that i did some coding in animation but i didn't succeed. I am using both translate and rotate.
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="1500" />
and rotate functions,
<rotate android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="600"
android:repeatMode="restart"
android:repeatCount="infinite"
android:interpolator="#android:anim/cycle_interpolator"/>
Actually my idea is in a specific time i want to move with specific angle. But i don't know the correct way to solve this task.
Please help me. sorry for my English.
All answers are acceptable
Thanks
Shankar
You have divided a circle in 12 parts in that image and that equals to 30 degrees per segment.
you have to rotate it like this to look proper
rotateDegree=[steps]*30;
use AlarmManager to trigger animation in specific time
EDIT:
to move your image in circular path with a radius you have to give a different pivot x and y
you can find it by tryng with
pivotX= 0 and pivotY=(negative value)
I hope this helps.

Android Flip Animation Grow and fade in from around , shrink and fade out to around?

I want to make a flip animation where one image will grow from around and it will shrink to one point. During growing it will be fade in and when shrink it will be fade out. I have tried many xml code but exactly this kind of code still unavailable to me.
For example, here is an example of what I've tried. It is growing from around but not fading in.
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fromXScale="1.4"
android:toXScale="0.0"
android:fromYScale="1.4"
android:toYScale="0.0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="1000"
/>
You can use 2 animation sets for that.
Animation set 1 will be for Scaling up and Fade in.
After animationSet1 is ended, start animation set 2
Animation set 2 will be for Shrinking and Fade out.

rotate image in android imageview

I want to build an application where, I have an image displayed via (ImageView).
and a textbox in the application.
I want to rotate the image in continuously for about 10 degree for every one second. when the image rotates, the textbox should display the number of times the image is rotated.
I tried rotating the image but every time the application crashes or doesn't show up in the screen.
Can someone help me with the code plz ??
Thanks
Create animation inn res/anim with this code
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:duration="36000" />
and in your Activity:
Animation rotate = AnimationUtils.loadAnimation(this, R.anim.rotate);
findViewById(R.id.yourImageId).startAnimation(rotate);
rotate.reset();
rotate.start();

Android fade out animation using Cosine function

I in my Android Honeycomb application there is a View which has a fade in and fade out animation. Here's most part of the animation code:
<scale
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="1.0"
android:toYScale="0.0"
android:pivotX="0%"
android:pivotY="0%"
android:duration="500" />
The way it's working right now the animation happens in a linear time but I want to do it according the Cosine function, that is from Cos(0) until Cos(0,5*pi) the fade out case.
Is it possible to do such thing?
Thank you.
You are free to create your own Interpolator. (See the interface description here.) This can then be applied with Animation.setInterpolator(Interpolator). Or, see this discussion for ways of applying custom Interpolators in XML.
If you don't want linear interpolation, you have choice between:
AccelerateDecelerateInterpolator, AccelerateInterpolator,
AnticipateInterpolator, AnticipateOvershootInterpolator,
BounceInterpolator, CycleInterpolator, DecelerateInterpolator,
LinearInterpolator, OvershootInterpolator
http://developer.android.com/reference/android/view/animation/Interpolator.html
So maybe what is the closest to a Cosine is:
AccelerateDecelerateInterpolator
An interpolator where the rate of change starts and ends slowly but
accelerates through the middle.

Categories

Resources