Android Bug? Multiple animations don't animate at the same time - android

So I'm applying one animation to multiple ImageViews (arrows) and using the AnimationSet class to do so, see below:
Animation animInstruct;
//Inside onCreate
animInstruct = AnimationUtils.loadAnimation(this, R.anim.anim_instructions);
ImageView arrow_bottomright = (ImageView) container.findViewById(R.id.arrow2);
ImageView arrow_bottomleft = (ImageView) container.findViewById(R.id.arrow3);
ImageView arrow_topleft = (ImageView) container.findViewById(R.id.arrow0);
ImageView arrow_topright = (ImageView) container.findViewById(R.id.arrow1);
AnimationSet start_atsame_time = new AnimationSet(true);
start_atsame_time.addAnimation(animInstruct);
arrow_topleft.setAnimation(start_atsame_time);
arrow_topright.setAnimation(start_atsame_time);
arrow_bottomleft.setAnimation(start_atsame_time);
arrow_bottomright.setAnimation(start_atsame_time);
start_atsame_time.start();
In my XML (anim_instructions):
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:duration="1000"
android:repeatCount="5" />
</set>
However, when I run the application (on an actual device), all arrows fade in/fade out at the same time but after the first iteration, one arrow takes longer to fade out while the others stay on track with each other. I don't know if its just the device's hardware limitations, an android bug, or something else?

Related

How to create an animation in a splash screen?

When we open a app we get different type of animated object or people moving around in the splash screen of an app for example like a person running while the app is loaded or the name of the app falls and a guy sits on it clicking photos.
How can we create one and what type of software do we use?
Can you suggest me some tutorials to follow?
use gif
OR
use Animation :
Ex) Awesome-looking customizable splash screen : AwesomeSplash
paste this xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/bounce_interpolator" >
<scale
android:duration="600"
android:fromXScale="1"
android:fromYScale="0.5"
android:pivotX="50%"
android:pivotY="0%"
android:toXScale="1.0"
android:toYScale="1.0" />
<alpha
android:duration="600"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
and on the splash screen
Animation animation = AnimationUtils.loadAnimation(contex, R.anim.blink);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE);
animation.setDuration(700);
and use this Animation like
final ImageView splash = (ImageView) findViewById(R.id.btnrecievecall);
splash.startAnimation(animation)
You can also use your own created gif images to show on the imageview at splash screen through Glide image loading and caching library.
Like :
ImageView imageView = (ImageView) findViewById(R.id.imageView);
GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
Glide.with(this).load(R.raw.gif_image).into(imageViewTarget);
1.. use gif file
or
2.. First using set animation effect, and after direct using this image splace screen.

How to rotate image slowly in android?

I want to rotate an Image in a slow way on Android.
I can do this by creating a Bitmap and by the
help of of Matrix class. But i don't know how to make it slow, like it should take 3 seconds to rotate.
Rotate
Rotate animation uses tag. For rotate animation required tags are android:fromDegrees and android:toDegrees which defines rotation angles.
Clock wise – use positive toDegrees value
Anti clock wise – use negative toDegrees value
rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<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"/>
</set>
Save in anim folder
public class AnimationActivity extends Activity{
ImageView img;
Animation rotate;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fadein);
img = (ImageView) findViewById(R.id.myimageid);
// load the animation
rotate = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.rotate);
img.startAnimation(rotate);
}
}
Complete Tutorial
In Kotlin you can use the ObjectAnimator do this super easily. For example:
ObjectAnimator.ofFloat(view, "rotationX", 180f).apply {
duration = 2000
start()
}
view: the view you want to rotate
"rotationX": the propertyName you want to alter.
"rotationX" gives you rotation into and out of the screen
"rotationY" gives you clockwise/counterclockwise rotation
180f: how many degrees you want to rotate the view
duration: the number of milliseconds the animation should take to complete
You can use rotate animation to achieve this.
Create anim folder under res directoy inside that place this xml.
rotate_around_center_point.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<rotate
android:duration="2500"
android:interpolator="#android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
</set>
Set animation to view like this.
ImageView animationTarget = (ImageView) this.findViewById(R.id.testImage);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_around_center_point);
animationTarget.startAnimation(animation);

Rotate animation to an ImageView in FrameLayout does not take effect

I have one ImageView in FrameLayout, and apply rotate animation to it. However, the animation does not take effect.
The animation resource file anim_blog.xml(located in res/anim):
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator" >
<rotate
android:fromDegrees="0.0"
android:toDegrees="360.0"
android:pivotX="50%p"
android:pivotY="50%p"
android:repeatCount="infinite"
android:duration="1200" />
</set>
The code in Activity is listed below:
Animation rotateAnim = AnimationUtils.loadAnimation(mCtx, R.anim.anim_blog);
rotateAnim.setDuration(Integer.MAX_VALUE);
mProgressIV.startAnimation(rotateAnim);
You are setting animation duration too large, change it as follows :
Animation rotateAnim = AnimationUtils.loadAnimation(mCtx, R.anim.anim_blog);
mProgressIV.startAnimation(rotateAnim);
please try what has done successfully from my end:
ImageView image = (ImageView)findViewById(R.id.imageView);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.anim_blog);
image.startAnimation(animation);
I created example here, you can check it out.

want a ImageView to come from upside down

i have a window and a imageview in it and i want the imageview to come from upside down animated effect how i do that
ImageView img_sliding=(ImageView)findViewById(R.id.img_sliding);
You have to write your own translate animation. a very good tutorial could be found here..
Here is a litte snipped that you can use and adapt it to your needs:
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="100%"
android:toYDelta="0%"
android:duration="300"
android:zAdjustment="top"
android:fillAfter="true" />
create a new xml file in res/anim and then set the animation to your imageview like this:
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.YOURANIMATION)
and set it to the iamgeView
imageview.setAnimation(anim);
Use a scale animation to scale from -1 to 1. This should have the effect of flipping the imageview

Android ScaleAnimation

I'd like to grow a view with each click using a ScaleAnimation. I've managed the effects of the animation persist after it has finished with the fillAfter, but the problem now is, the animation always starts from state 0 (as the View is defined in the XML) - on click the view resets and animates back to the state it was just after the first animation.
The animation is defined in an XML:
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1"
android:toXScale="1.5"
android:fromYScale="1"
android:toYScale="1.5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:fillAfter="true"
/>
I solved the issue by not resorting to animation defined in the XML, but rather doing
anim = new ScaleAnimation(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
and adjusting from/to each time I needed to expand it. I'm not so sure that's a good thing regarding performance, but it works nicely.
How exactly is the animation defined?
When defining ScaleAnimation with Java code, you can set fromX/fromY (look here) starting scaling factors, so I assume you can do the same with XML attributes.

Categories

Resources