1

What I want to make is many stars (currently I'm trying with only one) in Activity which will gloss with background and another picture made as their gloss. So, how I planned to do it is to instantiate AsyncTask from main Activity, which will manage all the animation for my stars. In Activity's layout I have one picture of a star, and one other picture of it's gloss, and which is behind the picture of the star, so all I have to do is to make sequent fading-in and fading-out for picture of star's gloss.

I'm making it with ObjectAnimator and AnimatorSet, which I'm honestly not sure if they're the best for performance, since I saw in documentations that there are AlphaAnimations.

Here is my code so far: Activity

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("");
}

and code for 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();
}

After to try to make this work, I'm getting error exception: "Animators may only be run on Looper threads" and that's where I stopped going further because I'm even not sure that this will be the best for performance, since I'm planning to have like 10 stars which are continuously animated.

How should I manage it properly?

Tommz
  • 3,393
  • 7
  • 32
  • 44
  • This was just what I needed: http://stackoverflow.com/questions/3906738/android-blinking-image-using-the-alpha-fade-animation – Tommz Sep 05 '13 at 13:08

0 Answers0