Is there a specific reason why the following animation does not play when set as drawable source of an image view under Android 5?
<?xml version="1.0" encoding="utf-8"?> <animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="750" android:drawable="#drawable/ic_status_battery_0" />
<item android:duration="750" android:drawable="#drawable/ic_status_battery_1" />
<item android:duration="750" android:drawable="#drawable/ic_status_battery_2" />
<item android:duration="750" android:drawable="#drawable/ic_status_battery_full" /> </animation-list>
Works perfectly on Android 4.4.
Okay, it seems that for AnimationDrawable objects that are embedded inside LevelListDrawable objects, there is only the following way to do it on Android 5:
LevelListDrawable lld = (LevelListDrawable) imageView.getDrawable();
Drawable current = lld.getCurrent();
if(current instanceof AnimationDrawable) {
((AnimationDrawable)current).start();
}
Related
Is there any way to make a ProgressBar like this.
Or can it be achieved by customizing RatingBar as an indicator?
If so, how would I be able to attach the lines in between the circles?
You can achieve this by using different images which represents different stages of your process
keep an imageview with visibility gone and make it visible when you want to display the same
in your drawable folder keep an xml like the following progressanimation.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/progressone" android:duration ="400" />
<item android:drawable="#drawable/progresstwo" android:duration="400" />
<item android:drawable="#drawable/progressthree" android:duration="400" />
<item android:drawable="#drawable/progressfour" android:duration="400" />
</animation-list>
and use this as background of your ImageView like follows
iv.setVisibility(View.VISIBLE);
iv.setBackgroundResource(R.drawable.progressanimation);
final AnimationDrawable mailAnimation = (AnimationDrawable) iv
.getBackground();
iv.post(new Runnable() {
public void run() {
if (mailAnimation != null)
mailAnimation.start();
System.out.println("anim wrkingggg");
}
});
here iv is your imageview.This code will change the background automatically.You can make the runnable run with your own timelimit.
I am developing an app in which i want to use frame animation. for this i am using animation-list. I am using android studio in which i created an anim folder inside the res folder.now i m not able to add any item. studio does not showing any tag like item when i pressed ctrl + space.
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
</animation-list>
You don't need to create anim folder. You have to paste the images and resource xmls in drawable folder. If you do not have drawable folder then create one inside of your res folder.
I have pasted 4 png images and a spin_animation.xml file inside of the drawable folder.
spin_animation.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/selected" android:oneshot="false">
<item android:drawable="#drawable/ani4" android:duration="500" />
<item android:drawable="#drawable/ani3" android:duration="500" />
<item android:drawable="#drawable/ani2" android:duration="500" />
<item android:drawable="#drawable/ani1" android:duration="500" />
</animation-list>
Suppose you want to replace a imageView
ImageView gyroView = (ImageView) findViewById(R.id.gyro);
to show animation. Set the background of that imageView
gyroView.setBackgroundResource(R.drawable.spin_animation);
Create an Animation Drawable object based on this background:
AnimationDrawable gyroAnimation = (AnimationDrawable) gyroView.getBackground();
Start the animation:
gyroAnimation.start();
For detail help check this.
in Android Studio, put the xml file in the res/drawable/ directory of your Module.
See these google offical doc below:
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
http://developer.android.com/guide/topics/graphics/drawable-animation.html
i want to create a progressbar in android like that image
i try to use
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/loadingicon"
android:pivotX="50%"
android:pivotY="50%" />
but i think it not meet in my requirement
Here is a good example to customize progressbar: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
U must draw all state of you future progress bar (img1.png, img2.png, img3.png, img4.png). put image to /res/drawable.
pb_animation.xml:
<animation-list android:id="#+id/myprogressrbar" android:oneshot="false">
<item android:drawable="#drawable/img1" android:duration="50" />
<item android:drawable="#drawable/img2" android:duration="50" />
<item android:drawable="#drawable/img3" android:duration="50" />
<item android:drawable="#drawable/img4" android:duration="50" />
</animation-list>
And then, in yor code:
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.pb_animation);
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
frameAnimation.start();
you could use an AnimationDrawable in combination with an ImageView and add a drawable for every state of your loading indicator, but a better way to this, is creating a new Style for a ProgressBar view (by extending de platform default style) and use your AnimationDrawable as loading indicator.
The Android styles are open source, so you can easily find them and extend them for your needs.
Good luck!
What is the appropriate action to take when you need to change the background image of a ProgressBar? I mean should use a .gif image like : http://2.bp.blogspot.com/-O7nsXfmgwSc/T6PQ0PVr6-I/AAAAAAAAAQI/-eXkEXj24-s/s1600/02.gif and if so will the foreground color of the bar fill the image file during the proccess ? Is there a way of creating an animation for the background of the bar ? What i am aiming for is to show the animation for as long the process does not cover the full bar.
you need to get all this gif frame image as individual and then set into the animation-list in xml file.
Here is your anim_progress.xml file code
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/i1" android:duration="500" />
<item android:drawable="#drawable/i2" android:duration="500" />
<item android:drawable="#drawable/i3" android:duration="500" />
<item android:drawable="#drawable/i4" android:duration="500" />
<item android:drawable="#drawable/i5" android:duration="500" />
<item android:drawable="#drawable/i6" android:duration="500" />
<item android:drawable="#drawable/i7" android:duration="500" />
<item android:drawable="#drawable/i8" android:duration="500" />
</animation-list>
set the duration for change as smooth effect for giving animated image like gif
Here is the code for using this file
ImageView iv = new ImageView(this);
iv.setBackgroundResource(R.drawable.anim_progress);
final AnimationDrawable mailAnimation = (AnimationDrawable) iv.getBackground();
iv.post(new Runnable() {
public void run() {
if ( mailAnimation != null ) mailAnimation.start();
}
});
setContentView(iv);
you can get all frames from gif file from this site.
http://gif-explode.com/
for example
http://2.bp.blogspot.com/-O7nsXfmgwSc/T6PQ0PVr6-I/AAAAAAAAAQI/-eXkEXj24-s/s1600/02.gif
this link just pass it and you will get all the frame images
I want an animated gif, since this isn't possible in Android I am using individual frames in a transition.
except it seems like the transition class only will show two frames ever! I saw other animation methods but they didn't seem to apply to what I was doing, or seemed old and convulated like for an older infant android build
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/activateanima"></item>
<item android:drawable="#drawable/activateanimb"></item>
<item android:drawable="#drawable/activateanimc"></item>
<item android:drawable="#drawable/activateanimc"></item>
<item android:drawable="#drawable/activateanimd"></item>
<item android:drawable="#drawable/activateanime"></item>
<item android:drawable="#drawable/activateanimf"></item>
<item android:drawable="#drawable/activateanimg"></item>
</transition>
How do I animate an image to behave like an animated gif, in place. no rotations or translations here. Using android 2.1+
Are you after a Frame animation? See: here. This will play a standing still animation.
Example from above site:
XML file saved at res/anim/rocket.xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/rocket_thrust1" android:duration="200" />
<item android:drawable="#drawable/rocket_thrust2" android:duration="200" />
<item android:drawable="#drawable/rocket_thrust3" android:duration="200" />
</animation-list>
To use:
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
rocketAnimation.start();
Just use a view flipper to flip between the images. Just define your in and out animations to be 0seconds long and they should be instantianous. (but use alpha to be sure). View flipper has the benefit of also auto animating and auto starting