我一直在试图使图像文件在现场旋转,并且挣扎着,我发现每个教程似乎都以不同的方式做到这一点。Android图像通过xml文件旋转
有人可以指出我要去哪里错了。
GamePlay.java
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class GamePlay extends Activity {
/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gameplay);
ImageView logo = (ImageView)findViewById(R.id.mainlogo);
logo.setBackgroundResource(R.anim.rotate);
AnimationDrawable frameAnimation = (AnimationDrawable) logo.getBackground();
frameAnimation.start();
}
}
rotate.xml
<?xml version="1.0" encoding="UTF-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="360"
android:drawable="@drawable/logo" />
gameplay.xml
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/mainlogo"
android:src="@drawable/logo">
</ImageView>
图像旋转你说?我会在OpenGL中将其作为纹理加载,然后使用正常的Open GL旋转命令来执行xml所说的操作。我也会使用简单的XML框架来解析XML。 – 2011-05-17 11:04:30
在rotate.xml中应该位于'res/anim'中,您应该添加一些属性,例如:android:repeatCount =“infinite”'android:duration =“1200”' – McIntosh 2012-11-06 12:04:46
我认为它正在旋转,你没有'android:duration =“”'它不能被看到。 – Aiapaec 2014-06-12 14:42:47