0
呃,我想在動畫播放後顯示我的文字。在這段代碼中,它同時執行動畫和文本,所以如何等到動畫播放完畢後才顯示文本?或者,如何在動畫播放之前隱藏文字?文字和動畫
package com.example.magic8ballers;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class Magic8Ballers extends Activity {
MediaPlayer song; //song reference
TextView answer; // TextView reference
Button button; // Button reference
Magic8BallersCode m8b; // M8B reference
// Animation object
Animation an;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_magic8_ballers);
// associate answer with TextView object with id textView1
answer = (TextView)findViewById(R.id.textView1);
// associate button with Button object with id button
button = (Button)findViewById(R.id.button1);
button.setText("Shake It!");
//Create new Magic8Ball object
m8b = new Magic8BallersCode();
song = MediaPlayer.create(Magic8Ballers.this, R.raw.magic);
//Shake it button animation
Button button = (Button) findViewById(R.id.button1);//reference to the
button that shakes it and provides prediction
final ImageView imgView =
(ImageView)findViewById(R.id.imageView1);//reference to the animation image
//Music Buttons
Button btnSound = (Button) findViewById(R.id.button2);//reference to the
button that turns on the song
Button btnSound2 = (Button) findViewById(R.id.button3);//reference to the
button that turns off the song
//Animation
final Animation an = AnimationUtils.loadAnimation(Magic8Ballers.this,
R.anim.animation);
//Button for animation
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
imgView.startAnimation(an);
String prediction = m8b.getAnswer();
// Set the label's text with the new prediction
answer.setText(prediction);
}
});
我會添加OnClick方法在我的動畫已經正在監聽? – user1876290
在onClick方法之前,您可以使用動畫setAnimationListener。動畫偵聽器從動畫接收通知。當你調用startAnimation()時,AnimationListener會爲你「傾聽」。 – secretlm