我想从 14 个 png 图像创建动画 drawable。我将 14 个图像添加到所有可绘制文件夹中,并创建了一个如下所示的动画列表,但没有出现,这是什么问题?
圈子.xml:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/f1" android:duration="50" />
<item android:drawable="@drawable/f2" android:duration="50" />
<item android:drawable="@drawable/f3" android:duration="50" />
<item android:drawable="@drawable/f4" android:duration="50" />
<item android:drawable="@drawable/f5" android:duration="50" />
<item android:drawable="@drawable/f6" android:duration="50" />
<item android:drawable="@drawable/f7" android:duration="50" />
<item android:drawable="@drawable/f8" android:duration="50" />
<item android:drawable="@drawable/f9" android:duration="50" />
<item android:drawable="@drawable/f10" android:duration="50" />
<item android:drawable="@drawable/f11" android:duration="50" />
<item android:drawable="@drawable/f12" android:duration="50" />
<item android:drawable="@drawable/f13" android:duration="50" />
<item android:drawable="@drawable/f14" android:duration="50" />
</animation-list>
布局xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start" />
<ImageView
android:id="@+id/imgCircle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
爪哇代码:
package pit.opensource.animation;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class CircleAnimationActivity extends Activity {
/** Called when the activity is first created. */
Button btnStart;
ImageView imgCircle;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnStart = (Button)findViewById(R.id.btnStart);
imgCircle = (ImageView) findViewById(R.id.imgCircle);
imgCircle.setBackgroundResource(R.drawable.circle);
AnimationDrawable ani = (AnimationDrawable) imgCircle.getBackground();
ani.start();
btnStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// ani.start();
}
});
}
}