我有10个图像文件。 我想每次按1-2,2-3,3-4 .... 1-2,2-3 ...的顺序依次播放图片,但是当我单击imageview时,只有第一个xml文件正在运行。请帮助我
imageView=(ImageView)findViewById(R.id.imageView);
imageView.setBackgroundResource(R.drawable.animationtesbih);
imageView.setClickable(true);
animation=(AnimationDrawable) imageView.getBackground();
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
animation=(AnimationDrawable) imageView.getBackground();
animation.start();
imageView.setBackgroundResource(R.drawable.a1);
imageView.setBackgroundResource(R.drawable.a2);
}
});
这是我的xml名称a1
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/t2" android:duration="70"/>
<item android:drawable="@drawable/t3" android:duration="70"/>
</animation-list>
此处为其他xml文件名animationtesbih
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/t1" android:duration="70"/>
<item android:drawable="@drawable/t2" android:duration="70"/>
</animation-list>
其他xml名称a2
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/t3" android:duration="70"/>
<item android:drawable="@drawable/t4" android:duration="70"/>
</animation-list>
答案 0 :(得分:0)
尝试一下:
animation=(AnimationDrawable) imageView.getBackground();
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
animation=(AnimationDrawable) imageView.getBackground();
animation.start();
imageView.setBackgroundResource(R.drawable.a1);
}
});