Android,正在从文档中绘制动画。。。不工作:(
我正在努力让这个例子起作用: 但当它开始的时候,它崩溃了(强制关闭),我不确定问题出在哪里,因为我是新来的 我的代码: (Java文件) 动画XML文件Android,正在从文档中绘制动画。。。不工作:(,android,animation,Android,Animation,我正在努力让这个例子起作用: 但当它开始的时候,它崩溃了(强制关闭),我不确定问题出在哪里,因为我是新来的 我的代码: (Java文件) 动画XML文件 <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android
<?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/note0" android:duration="50" />
<item android:drawable="@drawable/note1" android:duration="50" />
</animation-list>
所以我修改了代码:pastebin.com/ZtLf8J87
它可以工作;)动画xml应该始终在res/anim中决定。它引发错误的原因是因为您使用的是ImageView img=
(图像视图)findViewById(R.id.旋转车轮图像)
在设置内容视图之前,即
setContentView(R.layout.main)
为了跟踪错误和调试,请使用Logcat。Windows=>Open Perspective=>Logcat好的,按照你说的做了,我在“img.setBackgroundResource(R.drawable.spin_animation);”的java文件中得到了错误“spin_animation无法解决或不是字段”;“你确定res/drawable文件夹中有可绘制的spin_动画吗?我想是的,它看起来是这样的:我在drawable文件夹中看不到它。我只能在drawable-hdpi中找到图标和note1-note9。您写道“动画xml应该始终在res/anim中决定。”所以我将其移动到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/note0" android:duration="50" />
<item android:drawable="@drawable/note1" android:duration="50" />
</animation-list>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/note0"
android:id="@+id/spinning_wheel_image"></ImageView>
</LinearLayout>