android rotate animation, make it fluid - android

I have an ImageView that should rotate for 4 times. This is my xml of animation:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromDegrees="0"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="3"
android:repeatMode="restart"
android:toDegrees="360" />
but rotation is not fluid: there's a little delay from end of a rotation, and begin of next one. How can i fix it?

Try to rotate from 0 to 359. 0 and 360 is the same in that context.

why not create an animation the usual way, and if you want it to rotate four times, then create a loop that iterates four times, and for each iteration, it calls the animation. You have to optimize your code so that are no visible drags.

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

can only perform rotation of image view without holding it

Hi guys i uses the code below to perform rotation but it only rotates one time and goes back to its original position, how to let the image stay at the rotated position?
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="90"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:startOffset="0"
/>
xml file of my code
Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate);
a.startAnimation(rotation);
use:
anim.setFillAfter(true);
If fillAfter is true, the transformation that this animation performed
will persist when it is finished. Defaults to false if not set. Note
that this applies to individual animations and when using an
AnimationSet to chain animations.

How translate object accurately with different kind of value on the screen? Searching for truth

Hi I have a problem with controlling position of my object on the screen. When I create activity every object on the screen is placed with animation and troubles starting here. Firstly I tried to placed all things with pixel coordinates, which based on height and width of screen. I want to take it from device when activity starts. During the coding I think the better way will be use the % values cause I don't need to think about diferent screen resolution and stuff like this.
The picture shows, how I thought the screen looks with different values,but I'm wrong.I make the assumption, that the layout match to the parent, so it have nearly this same size as the screen
Cause the range of values for % and %p is from -100 to 100, so where is -100%, when I put something like -60%p I can't see it on the screen. I try to play with the object by changing the values and see results, but for example
object represented by
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillEnabled="true"
android:duration="3000"
android:startOffset="7000">
<translate
android:fromXDelta="2600"
android:toXDelta="0%p"
android:fromYDelta="-10"
android:toYDelta="-10%p"
/>
<rotate
android:fromDegrees="359"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
/>
is higher on the screen then object represented by:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillEnabled="true"
android:duration="3000"
android:startOffset="12000">
<rotate
android:fromDegrees="359"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
/>
<translate
android:fromXDelta="-599"
android:toXDelta="40%p"
android:fromYDelta="-499"
android:toYDelta="-10%p"
/>
I think they should be on this same vertical level, because android:toYDelta is the same.
When we are putting the values to xml code, we are placing the right top corner of the object in my opinion.
Please clear the way I think about coordinates of different type, and where are mistakes?
I would be grateful for every answer.

How to tilt a button along with its text...?

I am new to android development, can any one tell me how to rotate entire a button into 45 degrees along with text and button rect. I want to rotate permanently and i want on click listener on the same.
You need to use animations for that.
in your /res/anim/ you must create an xml file with this:
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:duration="0"
android:startOffset="0"
/>
and the in your Activity:
RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.YOUR_ANIM);
ranim.setFillAfter(true);
YourButton.setAnimation(ranim);
Apart from that it seems that there are some problems with diagonal rotations (a.k.a. 45 degrees) pre-honeycomb..

Efficient way of using TranslateAnimation to move something across the screen over and over

I've had trouble finding good documentation about animations in Android, but I managed to get my animation working. What I'm concerned about the way I did it is efficiency/performance.
My goal was to have a cloud image move across the screen over and over and repeat forever. To do this I ended up putting 2 identical ImageViews positioned over each other and defining 2 animations:
cloud_slide_exit.xml:
<translate
android:fromYDelta="0"
android:toXDelta="-100%p"
android:duration="25000"
android:repeatCount="infinite"
android:repeatMode="restart"
/>
cloud_slide_enter.xml:
<translate
android:fromYDelta="0"
android:fromXDelta="100%p"
android:duration="25000"
android:repeatCount="infinite"
android:repeatMode="restart"
/>
I applied the first animation to "image1" and the second to "image2." The first animation moves "image1" from right (on-screen) to left (off-screen) while the second animation moves "image2" (which starts off screen) from right (off-screen) to left (on-screen). The end result when you view both animations is that the image moves across the screen. When it reaches the left end of the screen it will start coming from the right side of the screen. This is the only way I could think of doing this.
Is there a more efficient way to go about doing this animation? I'd like to find a more efficient way because I actually have 3 clouds moving which means that I have 6 ImageViews/TranslateAnimations.
replace your code by following code:
cloud_slide_exit.xml:
<translate
android:fromXDelta="100%p"
android:toXDelta="0%p"
android:duration="25000"
android:repeatCount="infinite"
android:repeatMode="restart"
/>
cloud_slide_enter.xml:
<translate
android:fromXDelta="100%p"
android:toXDelta="0%p"
android:duration="25000"
android:repeatCount="infinite"
android:repeatMode="restart"
/>

Categories

Resources