問題があります。「ImageView」をクリックした後、描画可能なアニメーションを作成したい。質問に対する答えが見つかりましたが、見つかりませんでした。
私のコードは次のようになります:
import java.util.Locale;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class Talking extends Activity implements TextToSpeech.OnInitListener {
private TextToSpeech tts;
private Button button1;
private EditText editText1;
private AnimationDrawable penguinAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.talking);
tts = new TextToSpeech(this, this);
button1 = (Button) findViewById(R.id.button1);
editText1 = (EditText) findViewById(R.id.editText1);
// button on click event
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
speakOut();
}
});
ImageView penguin = (ImageView) findViewById(R.id.imageView1);
penguin.setBackgroundResource(R.drawable.penguin_anim);
penguinAnimation = (AnimationDrawable) penguin.getBackground();
}
@Override
public void onDestroy() {
// Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
protected void speakOut() {
// TODO Auto-generated method stub
String text = editText1.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
button1.setEnabled(true);
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
penguinAnimation.start();
return true;
}
return super.onTouchEvent(event);
}
}
これを使用して描画可能なアニメーションを作成しましたhttp://developer.android.com/guide/topics/graphics/drawable-animation.html