【问题标题】:How to make images blink simultaneously?如何让图像同时闪烁?
【发布时间】:2014-07-08 20:40:30
【问题描述】:

我有 5 张图片,我希望 img1 和 img2 同时闪烁 3 秒,然后 img3 和 img4 同时闪烁 3 秒。但是,我希望 img5 保持静止 3 秒,然后整个过程重新开始。

我的部分代码:

public class MainActivity extends Activity
{

 ...
    img1=(ImageView) findViewById(R.id.imageView1);
    img2=(ImageView) findViewById(R.id.imageView2);
    img3=(ImageView) findViewById(R.id.imageView3);
    img4=(ImageView) findViewById(R.id.imageView4);
    img5=(ImageView) findViewById(R.id.imageView5);


    img2.setVisibility(View.GONE);
    img3.setVisibility(View.GONE);
    ....

    anim = new AlphaAnimation(0.0f, 1.0f);
    anim.setDuration(500); //You can manage the time of the blink with this parameter
    anim.setStartOffset(30);
    anim.setRepeatMode(Animation.REVERSE);
    anim.setRepeatCount(20);

    ...

   img1.startAnimation(anim);

    AnimationListener animListener = new AnimationListener()
    {

        @Override
        public void onAnimationEnd(Animation arg0) {
            // TODO Auto-generated method stub
            img1.setVisibility(View.GONE);
            img2.setVisibility(View.VISIBLE);
            img2.startAnimation(anim2);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationStart(Animation animation) {

        }

    }; 
}

【问题讨论】:

  • img5 暂停,但 img1&2 img3&4 没有同时闪烁。仍然需要帮助来解决这个问题。

标签: android animation


【解决方案1】:

使用Handler 使img5 保持静止3 秒,然后启动动画。

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    @Override
    public void run() {
        // animateImg5();
    }
}, 3000);

【讨论】:

  • 非常感谢...这让我知道了使用什么。
猜你喜欢
  • 2012-08-20
  • 1970-01-01
  • 1970-01-01
  • 2020-08-27
  • 2012-08-22
  • 2015-04-25
  • 2012-05-13
  • 2010-10-29
  • 1970-01-01
相关资源
最近更新 更多