My question, is it possible to animate an item in an animation-list. Specifically, say you have:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true">
<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>
I want to fade the alpha of each <item>
rather than simply jump from one image to the next, is it possible?
With over a million downloads, Animation Desk is one of the best animation apps for Android that you can try. It has all the things that make an animation app great—a clutter-free user interface, an adequate amount of options, and a handful of ways to export the finished animation.
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.
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"?> <
You'll need to use tweened animations to do this. Essentially what you need to do is have two ImageView objects, one for the current image, and one for the new image. Create two tweened animations for res/anim/fadeout.xml:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="500"
android:duration="500" />
and res/anim/fadein.xml:
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:startOffset="500"
android:duration="500" />
Then use an ImageSwitcher widget to switch between the views:
@Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
LinearLayout ll = new LinearLayout( this );
ll.setOrientation( LinearLayout.VERTICAL );
setContentView( ll );
final ImageSwitcher is = new ImageSwitcher( this );
is.setOutAnimation( this, R.anim.fadeout );
is.setInAnimation( this, R.anim.fadein );
ImageView iv1 = new ImageView( this );
iv1.setImageResource( R.drawable.icon );
is.addView( iv1 );
is.showNext();
ll.addView( is );
Button b = new Button( this );
ll.addView( b );
b.setOnClickListener( new OnClickListener()
{
@Override
public void onClick( View v )
{
ImageView iv2 = new ImageView( MainActivity.this );
iv2.setImageResource( R.drawable.icon2 );
is.addView( iv2 );
is.showNext();
}
});
}
There is a series of articles on my blog about tweened animations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With