RT:
private ImageView animation;
private AnimationDrawable animationDrawable;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xml);
animation=(ImageView) findViewById(R.id.animation);
animation.setImageResource(R.drawable.huanyin);
animationDrawable=(AnimationDrawable)
animation.getDrawable();
animationDrawable.start();
运行不起来啊
private ImageView animation;
private AnimationDrawable animationDrawable;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.xml);
animation=(ImageView) findViewById(R.id.animation);
animation.setImageResource(R.drawable.huanyin);
animationDrawable=(AnimationDrawable)
animation.getDrawable();
animationDrawable.start();
运行不起来啊
发上来看看。
animationDrawable=(AnimationDrawable) animation.getBackground();
animationDrawable.start(); 换成这样试一下呢
private ImageView stage;
private Button start;
private Button stop; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity11); stage = (ImageView) findViewById(R.id.imageview);
animDrawable = new AnimationDrawable(); for (int i = 1; i <= 20; i++) {
int resId = getResources().getIdentifier(
"anim" + (i > 9 ? "_" : "_0") + i, "drawable",
"com.tarena.tts");
animDrawable.addFrame(getResources().getDrawable(resId), 150);
}
animDrawable.setOneShot(false);
stage.setImageDrawable(animDrawable); start = (Button) findViewById(R.id.start);
stop = (Button) findViewById(R.id.stop); start.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
animDrawable.start();
}
}); stop.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
animDrawable.stop();
}
});
}
}
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;public class Androd_DHJMActivity extends Activity
{
/** Called when the activity is first created. */ private ImageView animation;
private AnimationDrawable animationDrawable;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.xml);
animation = (ImageView) findViewById(R.id.animation);
}
@Override
protected void onResume()
{
super.onResume();
Animation anim = AnimationUtils.loadAnimation(this, R.drawable.huanyin);
if (anim != null)
{
anim.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation animation)
{ }
@Override
public void onAnimationRepeat(Animation animation)
{ }
@Override
public void onAnimationEnd(Animation animation)
{
Intent intent = new Intent(); intent.setClass(Androd_DHJMActivity.this, Main.class); Androd_DHJMActivity.this.startActivity(intent); Androd_DHJMActivity.this.finish();
}
});
animation.startAnimation(anim);
}
}}