How to set animated list as xml attribute

Is there a way to set and run xml animation-list as an xml attribute? I can install and run it programmatically as follows:

  ImageView img = (ImageView) findViewById(R.id.loadingImageView); img.setBackgroundResource(R.drawable.loading_animation); AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground(); frameAnimation.start(); 

Animation List:

 <animation-list xmlns:android="http://schemas.android.com/apk/res/android" //... android:oneshot="false" > <item android:drawable="@drawable/loading_anim_frame_one" android:duration="50"/> <item android:drawable="@drawable/loading_anim_frame_two" android:duration="50"/> 

and so on.

Is there a way to do this with xml only markup, i.e. no java code?

If not, is there a way to at least set it as an xml attribute and then run it programmatically?

I cannot use the rotation of a single drawable, since the animation consists of several sequences in a sequence.

+5
source share
3 answers

You can declare it as

 <set xmlns:android="http://schemas.android.com/apk/res/android" > <scale android:duration="700" android:fillAfter="false" android:fromXScale="0.0" android:fromYScale="0.0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.4" android:toYScale="1.4" /> <scale android:duration="400" android:fillBefore="false" android:fromXScale="1.4" android:fromYScale="1.4" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:toXScale="0.8" android:toYScale="0.8" /> </set> 

Just a link. You will have to change the type and parameters of the animation. And, according to my knowledge, you will need to run it using java.

Edit:

This is a link that may be useful for an animation list.

+16
source

I think you should download the animation first:

 Animation anim = AnimationUtils.loadAnimation(this, R.anim.animation_name); img.startAnimation(anim); 
+5
source

Adding an example with alpha and translation for future reference:

 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="400" android:fromYDelta="-100%p" android:toYDelta="0%p" /> <alpha android:duration="800" android:fromAlpha="0" android:toAlpha="1" /> </set> 
0
source

All Articles