我是安卓初学者。我需要在应用程序中实现逐帧动画,但我不知道它是如何完成的,请给我完整的逐帧动画示例。
最佳答案
您好,您可以通过此步骤来完成此操作。
Step 1 : Insert images in drawable folder which need for framing.
Step 2 : Create an xml for configure for FrameByFrame animation and place it into res/drawable folder. Here there are two images are use for animation is f1 and f2. android:duration defines time in milisecond for change frame.
<?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>
Step 3 : Create 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>
Step 4 : Finally execute in 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();
}
}
关于ANDROID - 逐帧动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32965690/