1

我想显示三个像开/关的图像视图,如果有人知道如何显示图像视图三次。我正在使用下面的代码

 totalTimeCountInMilliseconds = 180 * 1000;     
 timeBlinkInMilliseconds = 60 * 1000;
    private  boolean blink=true;
    countDownTimer = new CountDownTimer(totalTimeCountInMilliseconds,500) {
        @Override
        public void onTick(long leftTimeInMilliseconds) {
           if ( leftTimeInMilliseconds < timeBlinkInMilliseconds ) {
                if (blink) {
                    handImg.setVisibility(View.VISIBLE);
                } else {
                    handImg.setVisibility(View.INVISIBLE);
                }
                blink = !blink;     
                }
        }
        @Override
        public void onFinish() {
            handImg.setVisibility(View.INVISIBLE);
        }
    }.start();

请帮忙,提前谢谢:)

4

3 回答 3

2

无需创建 countDownTimer 或任何东西。

Android 为您提供漂亮的 alpha 动画。

干得好

Java 代码

ImageView myImageView = (ImageView) findViewById(R.id.imageview);
Animation myFadeInAnimation = AnimationUtils.loadAnimation(AbcActivity.this, R.anim.blink);
myImageView.startAnimation(myFadeInAnimation);

眨眼.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500"
    android:fromAlpha="0.0"
    android:repeatCount="3"  <---- Image will blink 3 times
    android:repeatMode="reverse"
    android:toAlpha="1.0" />
于 2012-07-02T05:30:13.127 回答
0

您可以使用 Timer 类

    autoUpdate = new Timer();
    autoUpdate.schedule(new TimerTask() {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                public void run() {
                    YourLogic();
                }
            });
        }
    }, 0, 180 * 1000); // updates each 3 min  

YourLogic 函数 con 是这样的:

private void YourLogic() {
if ( leftTimeInMilliseconds < timeBlinkInMilliseconds ) {   
if (blink) {   
handImg.setVisibility(View.VISIBLE);   
} else {    
handImg.setVisibility(View.INVISIBLE);   
}   
blink = !blink   
}
        } 

我希望这能帮到您

于 2012-07-02T05:25:13.703 回答
0

试试这个

final AlphaAnimation  blinkanimation=   new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
blinkanimation.setDuration(300); // duration - half a second
blinkanimation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
blinkanimation.setRepeatCount(3); // Repeat animation infinitely
blinkanimation.setRepeatMode(Animation.REVERSE);

并将此动画设置为您的图像视图,如下所示

imageview.setAnimation(blinkanimation2);  or 
imageview.startAnimation(blinkanimation2);  

根据您的要求更改动画的持续时间和重复次数

于 2012-07-02T05:30:53.527 回答