逐帧动画

时间:2010-07-20 13:16:10

标签: android eclipse animation sdk frame

当我尝试在Eclipse中编写逐帧动画时,它给了我一个bug。我在互联网上发现了一些东西,说他们搞砸了sdk教程文档,但我不禁想知道 android:id =“selected”意味着什么应该放在引号中。

另外,有人可以向我解释帧动画教程的最后一部分吗? http://developer.android.com/guide/topics/resources/animation-resource.html#Frame 你在文件名 .Java中放了另一个代码吗?如果是的话,你把它放在哪里? 我无法理解将第二个不是XML的代码放在哪里。我想我需要知道下面的代码是什么以及应该去哪里:

ImageView fileimage = (ImageView) findViewById(R.id.file_image);
fileimage.setBackgroundResource(R.drawable.file_image2);

fileAnimation = (AnimationDrawable)fileimage.getBackground();
fileAnimation.start();

但这是我使用的XML代码:

 <animation-list android:id="selected" android:oneshot="false">
 <item android:drawable="@drawable/filename" android:duration="200" />
 <item android:drawable="@drawable/filename2" android:duration="200" />
 </animation-list>

是否应删除或添加任何内容?我不知道还能做什么,因为我需要启动动画并获得该代码(第一个),但我不知道它在哪里,或者我是否需要另外的代码。

1 个答案:

答案 0 :(得分:3)

这就是我实施它的方式。

在你的主java文件中你应该有这样的东西。

public class Main extends Activity { 
AnimationDrawable mainanimation;

public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 
     setContentView(R.layout.main);

     ImageView mainimage = (ImageView) findViewById(R.id.MainAnim);
     mainimage.setBackgroundResource(R.anim.mainanim);
     mainanimation = (AnimationDrawable) mainimage.getBackground();

因此,将main.xml布局文件中的ImageView设置为包含动画的xml(R.id.MainAnim)

然后在您编写的MainAnim.xml(位于res / anim)文件中

<?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/image1" android:duration="2000" />
<item android:drawable="@drawable/image2" android:duration="2000" />
</animation-list>

现在,image1和image2将在每个2秒前后来回交替。我也没有使用andriod:id =“selectable”。

总结一下,你需要3个文件。您的Main.java,您的main.xml布局文件以及位于res / anim中的mainanim.xml文件。还有你在drawable文件夹中的2张图片。

希望能稍微清理一下。

相关问题