アニメーションとクロノメーターを視野に入れたクラスがあります。これは私のonCreateメソッドの内容です:
chronometer = ((Chronometer) findViewById(R.id.clock_time));
chronometer.setOnChronometerTickListener(this);
chronometer.start();
v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
final SurfaceView surfaceViewTimer = (SurfaceView) findViewById(R.id.surface_view_timer);
final RelativeLayout timeView = (RelativeLayout) findViewById(R.id.time_view);
ViewTreeObserver observer = timeView.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int animationDuration = getIntent().getIntExtra(
MainActivity.TOTAL_TIME, -1);
TranslateAnimation surfaceGrowingAnimation = new TranslateAnimation(
0, 0, timeView.getHeight(), 0);
surfaceGrowingAnimation.setDuration(animationDuration * 1000);
surfaceViewTimer.startAnimation(surfaceGrowingAnimation);
私はクロノメーターにこの他の方法を持っています:
@Override
public void onChronometerTick(Chronometer chronometer) {
int intervalOfVibration = getIntent().getIntExtra(
MainActivity.VIBRATION_INTERVAL, -1);
long elapsedMillis = (SystemClock.elapsedRealtime() - ((Chronometer) findViewById(R.id.clock_time))
.getBase()) / 1000;
if (((elapsedMillis % intervalOfVibration) == 0) && (elapsedMillis > 0))
v.vibrate(300);
}
しかし、私のアニメーションはクロノメーターの各ティックで再開します。
どうすればこれを修正できますか?
今、私はこれらのエラーを受け取ります:
11-26 17:58:57.908: W/dalvikvm(15596): threadid=3: thread exiting with uncaught exception (group=0x2aaca228)
11-26 17:58:57.908: E/AndroidRuntime(15596): Uncaught handler: thread main exiting due to uncaught exception
11-26 17:58:57.908: E/AndroidRuntime(15596): java.lang.IllegalStateException: This ViewTreeObserver is not alive, call getViewTreeObserver() again
11-26 17:58:57.908: E/AndroidRuntime(15596): at android.view.ViewTreeObserver.checkIsAlive(ViewTreeObserver.java:492)
11-26 17:58:57.908: E/AndroidRuntime(15596): at android.view.ViewTreeObserver.removeGlobalOnLayoutListener(ViewTreeObserver.java:339)
11-26 17:58:57.908: E/AndroidRuntime(15596): at com.activities.TimerActivity$1.onGlobalLayout(TimerActivity.java:64)
11-26 17:58:57.908: E/AndroidRuntime(15596): at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:549)