I am android beginner. I need to implement frame by frame animation in app but hows it done I didn't know please give me complete example of Frame By Frame animation.
答案 0 :(得分:4)
您好,您可以通过此步骤执行此操作。
步骤1:将图像插入需要框架的可绘制文件夹中。
步骤2:为FrameByFrame动画创建一个xml,并将其放入res / drawable文件夹。 这里有两个用于动画的图像是f1和f2。 android:duration定义更改帧的时间(以毫秒为单位)。
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="@drawable/f1"
android:duration="50"/>
<item
android:drawable="@drawable/f2"
android:duration="50"/>
</animation-list>
第3步:创建main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
步骤4:最后在MainActivity.java中执行
public class MainActivity extends Activity {
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Imageview in which images load one by one like Frame By Frame
iv = (ImageView) findViewById(R.id.imageView1);
//Bind xml which is configure animation.
AnimationDrawable ad = (AnimationDrawable) getResources().getDrawable(
R.drawable.sam);
iv.setBackgroundDrawable(ad);
//Start animation
ad.start();
//For stop animation you can use ad.stop();
}
}
答案 1 :(得分:0)
我现在想到的两种方式是: