通过XML文件的Android图像旋转 [英] Android image rotate via xml file
本文介绍了通过XML文件的Android图像旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直试图做一个镜像文件旋转当场和我在努力,每个教程中,我发现,似乎这样做以不同的方式。
I've been attempting to make a image file rotate on the spot and am struggling, every tutorial I find seems to do this in a different way.
可有人点我要去哪里错在这里。
Can someone point where I'm going wrong here.
GamePlay.java
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
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
gameplay.xml
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/mainlogo"
android:src="@drawable/logo">
</ImageView>
推荐答案
更改rotate.xml到
Change rotate.xml to
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1200"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toDegrees="360" />
</set>
将其放入RES /动画/文件夹
place it in res/anim/ folder
和尝试这个启动动画
ImageView logo = (ImageView)findViewById(R.id.mainlogo);
Animation rotateAnimation = AnimationUtils.loadAnimation(context,
R.anim.rotate);
logo.startAnimation(rotateAnimation);
这篇关于通过XML文件的Android图像旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文