我的问题是,有没有可能在动画列表中设置一个项目的动画。具体地说,假设你有:
<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>我想淡化每个<item>的alpha,而不是简单地从一个图像跳到下一个图像,这可能吗?
发布于 2011-06-03 16:09:43
您需要使用补间动画来完成此操作。实际上,您需要做的是拥有两个ImageView对象,一个用于当前图像,另一个用于新图像。为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" />和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" />然后使用ImageSwitcher小部件在视图之间切换:
@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();
}
});
}在my blog上有一系列关于补间动画的文章。
https://stackoverflow.com/questions/6223891
复制相似问题