java - How to start drawable animation after click ImageView? -
i have problem. want make drawable animation after click "imageview". found answer question , didn't find.
my code looks like:
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 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 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); } }
i made drawable animation using http://developer.android.com/guide/topics/graphics/drawable-animation.html
add
penguinanimation.start()
in
speakout()
method, calling imageview clicklistener
.
Comments
Post a Comment