Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set animation-list as xml attribute

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

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

The animation-list is:

<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"/>

etcetera.

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

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

I can't use rotation of a single drawable since the animation consists of several drawables in sequence.

like image 833
Pierre Rymiortz Avatar asked Nov 26 '12 08:11

Pierre Rymiortz


People also ask

What is pivotX and pivotY in android?

The pivotX and pivotY is the central point of the animation. So for example if you want to do Zoom In animation you can use this <? xml version="1.0" encoding="utf-8"?> <

What are two different types of view animations?

There are two types of animations that you can do with the view animation framework: Tween animation: Creates an animation by performing a series of transformations on a single image with an Animation. Frame animation: or creates an animation by showing a sequence of images in order with an AnimationDrawable .

In which folder animation will be stored?

You can find the anim folder by navigating to the app > res > anim. Then go to the anim > right-click > New > Animation Resource File as shown in the below image.

Which statement should be placed in an animation list to make an animation play once and then stop?

You might notice the android:oneshot=”true” in both of these code snippets, which is simply an attribute of the animation-list for playing the animation once and then stopping. If this is set to “false,” the animation will play on repeat.


1 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 reference. You would have to change animation type and parameters. And as per my knowledge, you will have to start it using java.

Edit:

This is the link that can be helpful for animation list

like image 166
MysticMagicϡ Avatar answered Oct 31 '22 10:10

MysticMagicϡ