如何管理Android中的背景动画?

时间:2013-09-05 11:57:20

标签: android animation

我想要制作的是活动中的许多明星(目前我只尝试一个),这些明星将以背景和另一张照片作为光泽。所以,我计划如何实现它是从主AsyncTask实例化Activity,它将管理我的星星的所有动画。在“活动”的布局中,我有一张星星的照片,另外一张有关它的光泽照片,这张照片背后是星星的照片,所以我所要做的就是让星星的照片顺序淡入淡出光泽。

我正在使用ObjectAnimator和AnimatorSet制作它,我真的不确定它们是否是性能最好的,因为我在文档中看到有AlphaAnimation s。

到目前为止,这是我的代码: 的活动

public class LogoActivity extends Activity{


private AsyncLogoAnimation asyncLogoAnimation;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.proba_logo_activity);


    asyncLogoAnimation = new AsyncLogoAnimation(this);
    asyncLogoAnimation.execute("");
}

AsyncTask 的代码:

public class AsyncLogoAnimation extends AsyncTask<String, String, String>  {

private ObjectAnimator animator_FADEOUT;
private ObjectAnimator animator_FADEIN;
private AnimatorSet aSet;

// instanca od loga
private LogoActivity instance;

public AsyncLogoAnimation(LogoActivity instance){
    this.instance = instance;

    ImageView Gloss = (ImageView) instance.findViewById(R.id.gloss);
    animator_FADEOUT = ObjectAnimator.ofFloat(Gloss, "alpha", 0f);
    animator_FADEOUT.setDuration(1000);

    animator_FADEIN = ObjectAnimator.ofFloat(Gloss, "alpha",  0f, 1f);
    animator_FADEIN.setDuration(1000);


    aSet = new AnimatorSet();
    aSet.playSequentially(animator_FADEOUT, animator_FADEIN);


}


@Override
protected String doInBackground(String... params) {

    aSet.start();
}

在尝试完成这项工作之后,我遇到错误异常:“动画师可能只能在Looper线程上运行”而这就是我停止前进的地方因为我甚至不确定这对于性能是否最佳因为我计划有10颗不断激活的星星。

我该如何妥善管理?

0 个答案:

没有答案
相关问题