1

オン/オフのような3つの画像ビューを表示したいのですが、画像ビューを3回表示する方法を知っている人がいる場合は、以下のコードを使用しています。

 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は素晴らしいアルファアニメーションを提供します。

どうぞ

Javaコード

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

flash.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

これを試して

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);

以下に示すように、このアニメーションをurimageviewに設定します

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

要件に応じてアニメーションの継続時間と繰り返し回数を変更する

于 2012-07-02T05:30:53.527 に答える
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 関数は次のようになります。

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 に答える