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
Related
How to have this blink effect on my notification icon during a download file, like that:
MY ANSWER
Just use this native drawable android.R.drawable.stat_sys_download
mBuilder.setContentTitle(title)
.setContentText(filename)
.setSmallIcon(android.R.drawable.stat_sys_download);
Try using an animation drawable.
For example:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="#drawable/frame1On" android:duration="1000" />
<item android:drawable="#drawable/frame2Off" android:duration="1000" />
</animation-list>
Where frame1On on is the image highlighted, and frame2Off is the image greyed out. Add more frames if necessary.
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();
}
I am creating a loading screen using animation-list but I've run into a error where I cannot get access to my res/drawable folders inside my xml file. The error I get is "No resource found that matches the given name (at 'drawable' with value '#drawable/loadingwave0.png')"
Inside the directory res/anim/ My xml code is simple:
<?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/loadingwave0.png"
android:duration="100" />
</animation-list>
I've noticed that inside my item tag, Eclipse does not predict any drawable resources even though I've already copied them(not referenced) to the drawable folders(hdpi, ldpi, mdpi). My .png images can be accessed through my AndroidManifest.xml file if I use the code
<item android:icon="#drawable/loadingwave0.png"/>
for making sure the drawable folders can be accessed. I have already cleaned and refreshed my project multiple times.
Any help would be greatly appreciated.
you should use :
<?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/loadingwave0"
android:duration="100" />
</animation-list>
the resource id is the file name without extension.
I found below link for use of Gif at ImageView But I don't know how use it.
I want show Gif Image at ImageView from sdcard or assets folder.
help me . Thank
http://www.java2s.com/Open-Source/Android_Free_Code/ImageView/Download_Free_code_ImageViewEx.htm
also I use Tutorial: How to play animated GIFs in Android.but when I use that.it show's only one gif at Activity.I want show many gif picture at one Activity and at different locations of screen.
if you wanna show gif animation, Try this because android and ios can't support this kind of animation
Create in drawable folder my_gif.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/image_1" android:duration="100" />
<item android:drawable="#drawable/image_2" android:duration="100" />
<item android:drawable="#drawable/image_3" android:duration="100" />
</animation-list>
add parameter for your img view
android:src="#drawable/my_gif"
When I try to code a frame-by-frame animation in Eclipse, It gives me a bug. I found something on the internet that says they screwed up in the sdk tutorial documentation but I cannot help but wonder what android:id="selected" means or what should be put in the quotations instead.
Also, can somebody explain the last part of the frame animation tutorial to me?
http://developer.android.com/guide/topics/resources/animation-resource.html#Frame
Do you put another code in the filename.Java, and if so, where do you put it?
I cannot understand where to put the second code that is not XML. I think I need to know what the code below is and where it should go:
ImageView fileimage = (ImageView) findViewById(R.id.file_image);
fileimage.setBackgroundResource(R.drawable.file_image2);
fileAnimation = (AnimationDrawable)fileimage.getBackground();
fileAnimation.start();
But here is the XML code I used:
<animation-list android:id="selected" android:oneshot="false">
<item android:drawable="#drawable/filename" android:duration="200" />
<item android:drawable="#drawable/filename2" android:duration="200" />
</animation-list>
Should anything be removed or added from that? I don't know what else to do, because I need to start the animation and have the code for that (1st one) but I don't know where it goes, or if I need another code along with it.
This is how I implemented it.
In your main java file you should have something like this.
public class Main extends Activity {
AnimationDrawable mainanimation;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
ImageView mainimage = (ImageView) findViewById(R.id.MainAnim);
mainimage.setBackgroundResource(R.anim.mainanim);
mainanimation = (AnimationDrawable) mainimage.getBackground();
So you set the ImageView in your main.xml layout file to the xml that contains the animation (R.id.MainAnim)
Then in your MainAnim.xml (located in res/anim) file you write
<?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/image1" android:duration="2000" />
<item android:drawable="#drawable/image2" android:duration="2000" />
</animation-list>
Now image1 and image2 will alternate back and forth at 2 seconds each. Also I didn't use andriod:id="selectable".
To recap you need 3 files. Your Main.java, your main.xml layout file, and your mainanim.xml file located in res/anim. Also your 2 images in the drawable folder.
Hope that clears it up a little.