2012-07-12 11 views
15

私は画像ギャラリーアプリを作っています。私は現在、一番下にテキストビューを持つイメージビューを持っています。現在、それはちょうど半透明です。フェードインしたい、3秒待ってから、90%をフェードアウトします。それに焦点を当てたり、新しい画像を読み込んだりすると、それが繰り返されます。私はダースのページを読んで、いくつかのことを試みましたが、成功しませんでした。私が得るのは、フェードインとインスタントフェードアウトです。TextViewアニメーション - フェードイン、待機、フェードアウト

+0

Nothing yet ???? ???? –

答えて

3

インスタントフェードアウトを防ぐために余分なアニメーションオブジェクト(アルファを変更しない)を使用して、フェードインエフェクトのanimationListenerを設定し、フェードインのonアニメーションの余分なアニメーションオブジェクトを開始することができます、その後、あなたはフェードアウト余分なアニメーションオブジェクトのアニメーションの最後に、下のリンクを試し始める、それは私がフェードをループのための私のプロジェクトで使用されてきたソリューションです。..

Auto fade-effect for textview

39
protected AlphaAnimation fadeIn = new AlphaAnimation(0.0f , 1.0f) ; 
protected AlphaAnimation fadeOut = new AlphaAnimation(1.0f , 0.0f) ; 
txtView.startAnimation(fadeIn); 
txtView.startAnimation(fadeOut); 
fadeIn.setDuration(1200); 
fadeIn.setFillAfter(true); 
fadeOut.setDuration(1200); 
fadeOut.setFillAfter(true); 
fadeOut.setStartOffset(4200+fadeIn.getStartOffset()); 

完全に白い背景のために動作します。それ以外の場合は、AlphaAnimationクラスをインスタンス化するときに値を切り替える必要があります。このように:

AlphaAnimation fadeIn = new AlphaAnimation(1.0f , 0.0f); 
AlphaAnimation fadeOut = new AlphaAnimation(0.0f , 1.0f); 

これは、黒い背景と白いテキストの色で機能します。

2

をお手伝いしますテキストビューのイン/フェードアウトアニメーション:

private void setUpFadeAnimation(final TextView textView) { 
    // Start from 0.1f if you desire 90% fade animation 
    final Animation fadeIn = new AlphaAnimation(0.0f, 1.0f); 
    fadeIn.setDuration(1000); 
    fadeIn.setStartOffset(3000); 
    // End to 0.1f if you desire 90% fade animation 
    final Animation fadeOut = new AlphaAnimation(1.0f, 0.0f); 
    fadeOut.setDuration(1000); 
    fadeOut.setStartOffset(3000); 

    fadeIn.setAnimationListener(new Animation.AnimationListener(){ 
     @Override 
     public void onAnimationEnd(Animation arg0) { 
      // start fadeOut when fadeIn ends (continue) 
      textView.startAnimation(fadeOut); 
     } 

     @Override 
     public void onAnimationRepeat(Animation arg0) { 
     } 

     @Override 
     public void onAnimationStart(Animation arg0) { 
     } 
    }); 

    fadeOut.setAnimationListener(new Animation.AnimationListener(){ 
     @Override 
     public void onAnimationEnd(Animation arg0) { 
      // start fadeIn when fadeOut ends (repeat) 
      textView.startAnimation(fadeIn); 
     } 

     @Override 
     public void onAnimationRepeat(Animation arg0) { 
     } 

     @Override 
     public void onAnimationStart(Animation arg0) { 
     } 
    }); 

    textView.startAnimation(fadeOut); 
} 

これが助けてくれることを願っています!

関連する問題