2016-08-29 3 views
0

私は自分のアクティビティにTextViewを持っています。テキストを表示してから、アクティビティが開始されるたびにフェードアウトして非表示にしたいと思います。TextViewがフェードアウトして消える

私は有線の状況があります(TextViewはフェードアウトされています)が、ほとんどの場合、機能していません(onAnimationEndの機能に到達できませんでした)。ここで

はそれのために私のコードです:

protected void onResume() { 
    fadeOut = new AlphaAnimation(1.0f , 0.0f) ; 
    fadeOut.setDuration(5000); 
    //fadeOut.setFillBefore(true); 
    fadeOut.setFillAfter(true); 
    //fadeOut.setStartOffset(1000); 


    fadeOut.setAnimationListener(new Animation.AnimationListener() { 
     @Override 
     public void onAnimationStart(Animation animation) { 
      Log.d(TAG, "fade out start"); 
     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      Log.d(TAG, "fade out end"); 

      textRotateHint.setVisibility(View.INVISIBLE); 
     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 
      Log.d(TAG, "fade out repeat"); 
     } 
    }); 

    textRotateHint.setVisibility(View.VISIBLE); 
    textRotateHint.setText(R.string.rotation_hint); 
    textRotateHint.startAnimation(fadeOut); 

    super.onResume(); 
} 
+0

これは、 'onResume()'が必ずしも呼び出されるとは限らないことを意味します。 – qantik

+0

私のデバッグのために、私はそれが到達したことを見ることができます:Log.d(TAG、 "fade out start");しかし、決して行く:Log.d(TAG、 "フェードアウト終了"); –

答えて

2

あなたは、単純な値のアニメーターを使用することができます。

ValueAnimator valueAnimator = ValueAnimator.ofFloat(1f, 0f); 
valueAnimator.setDuration(5000); 
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
    @Override 
    public void onAnimationUpdate(ValueAnimator animation) { 
     float alpha = (float) animation.getAnimatedValue(); 
     mTextView.setAlpha(alpha); 
    } 
}); 
valueAnimator.start(); 
+0

それは動作します!ありがとう! –

関連する問題