我的问题是,是否可以为动画列表中的项目设置动画.具体来说,说你有:
<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>
Run Code Online (Sandbox Code Playgroud)
我想淡化每个的alpha <item>而不是简单地从一个图像跳到下一个图像,这可能吗?
您需要使用补间动画来执行此操作。本质上,您需要做的是拥有两个 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" />
Run Code Online (Sandbox Code Playgroud)
和 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" />
Run Code Online (Sandbox Code Playgroud)
然后使用 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();
}
});
}
Run Code Online (Sandbox Code Playgroud)
我的博客上有一系列关于补间动画的文章。
| 归档时间: |
|
| 查看次数: |
5955 次 |
| 最近记录: |