2011-01-05 16 views
2

我試圖通過監視第一個動畫的onanimationEnd回調來完成一個動畫。但是Android爲當我試圖做到這一點,以下錯誤:我可以在前一個的onanimationEnd回調中啓動Android動畫嗎?

錯誤 - 在類型AnimationUtils的方法loadAnimation(上下文,INT)不適用於參數(新Animation.AnimationListener() {},INT)

我試圖用的回答在這個崗位: --- Android Animation one after other 這我理解的意思,我應該只是開始動畫中移動所有的東西回調,但我這樣做時,我得到了以下錯誤:

錯誤 - 無法引用在di中定義的內部類中的非最終變量fade3不同的方法

我在這裏丟失什麼?


******代碼的第一個示例**********


package com.smartproducts.dragracepro; 

import android.content.Intent; 
import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.util.TypedValue; 
import android.view.Gravity; 
import android.view.View; 
import android.view.animation.Animation; 
import android.view.animation.Animation.AnimationListener; 
import android.view.animation.AnimationUtils; 
import android.view.animation.LayoutAnimationController; 
import android.widget.ImageView; 
import android.widget.TableLayout; 
import android.widget.TableRow; 
import android.widget.TextView; 


public class DragRaceProSplashActivity extends DragRaceProActivity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 

     //animate title fade in 
     TextView programtitle = (TextView) findViewById(R.id.TextViewTopTitle); 
     Animation fade1 = AnimationUtils.loadAnimation(this,R.anim.fade_in); 
     programtitle.startAnimation(fade1); 

     //show introduction and logo for Smart Shocks 
     fade1.setAnimationListener(new AnimationListener(){   
      @Override 
      public void onAnimationEnd(Animation fade1) 
      { 
***************   
ERROR IS HERE> Animation fade3 = AnimationUtils.loadAnimation(this,R.anim.fade_in2); *************** 
      ImageView sslogo = (ImageView) findViewById(R.id.ImageView03); 
       sslogo.setVisibility(View.VISIBLE); 
       sslogo.startAnimation(fade3); 
      } 

      @Override 
      public void onAnimationRepeat(Animation animation) {} 

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

    } 
+0

好movinbg動畫監聽器外的fade3並聲明它最終工作,但爲什麼? Adroid試圖告訴我什麼? – 2011-01-05 07:36:24

+0

如果您將問題的格式設置得更好一些,會更容易理解。 – 2011-01-05 08:00:36

回答

0
Animation fade3 = AnimationUtils.loadAnimation(this,R.anim.fade_in2); 

this指的是動畫,而不是你的上下文因爲你在監聽器中調用它,如果你想使用這個代碼,那麼你需要創建一個你的上下文的全局變量,並使用該變量代替this

+0

或者只是調用「DragRaceProSplashActivity.this」而不是「this」 – marmor 2013-11-14 13:54:00

相關問題