[英]Can I launch an Android animation in the onanimationEnd callback of the previous one?
我試圖通過監視第一個動畫的onanimationEnd回調來啟動另一個動畫完成的動畫。 但是,當我嘗試執行此操作時,Android給出以下錯誤:
錯誤-AnimationUtils類型的方法loadAnimation(Context,int)不適用於自變量(新的Animation.AnimationListener(){},int)
我試圖在這篇文章中使用答案:--- 一個接一個的Android動畫,我的解釋是我應該將除開始動畫之外的所有內容都移出回調,但是這樣做時,出現以下錯誤:
錯誤-無法在使用其他方法定義的內部類中引用非最終變量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) {}
});
}
Animation fade3 = AnimationUtils.loadAnimation(this,R.anim.fade_in2);
this
是指動畫,而不是您在偵聽器中調用它時所使用的上下文,如果要使用此代碼,則需要創建上下文的全局變量並使用該變量代替this
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.