Android为动画列表设置动画
我的问题是,是否可以在动画列表中设置项目的动画。具体来说,假设您有:Android为动画列表设置动画,android,animation,Android,Animation,我的问题是,是否可以在动画列表中设置项目的动画。具体来说,假设您有: <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:dra
<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>
我想淡入每个
的alpha,而不是简单地从一个图像跳到下一个图像,这可能吗?您需要使用tweed动画来实现这一点。基本上,您需要做的是有两个ImageView对象,一个用于当前图像,另一个用于新图像。为res/anim/fadeout.xml创建两个tweed动画:
<?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" />
有一系列关于Tweed动画的文章。不太确定这是否是我想要的。我正在尝试在应用程序下载数据时制作一个启动屏幕的动画,这样我就不需要简单的静态图像。动画将包含至少4个图像,动画应该自己发生——没有用户交互。我使用一个按钮使代码保持简单。您可以使用带有背景线程的ImageSwitcher定期更改图像。
<?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" />
@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();
}
});
}