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.
Related
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?
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.
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);
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
I have a gridview, and I am trying to achieve a fly in effect on the images within it. This would be very similar to the effect seen when you load up gallery 3D and your image folders "drop in".
I have googled around the subject, and think I need to use a ViewAnimator and generate the animation through that: http://developer.android.com/reference/android/widget/ViewAnimator.html#setInAnimation(android.view.animation.Animation)
However, I am not sure and any help on how to achieve this whatsoever would be very welcome!
Regards
Mark
Do you want the fly-in animation per grid, or for the entire view?
For the entire view, use this:
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.flyin);
findViewById(R.id.YourViewId).setAnimation(anim);
anim.start();
Then specify your animation in a file flyin.xml like this:
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="true">
<scale android:interpolator="#android:anim/decelerate_interpolator"
android:fromXScale="1.0" android:toXScale="0.0"
android:fromYScale="1.0" android:toYScale="0.0"
android:pivotX="50%" android:pivotY="50%"
android:fillAfter="false" android:duration="250"/>
</set>
Put that file in your res/anim-directory.