[英]Android Animation Background (Rotate, Translate)
I make my first small game. 我做我的第一个小游戏。 I use the Rotate Animation, that was given from Android. 我使用的是Android提供的旋转动画。 I write this code in every class file: 我在每个类文件中编写以下代码:
this.overridePendingTransition(R.anim.rotate, R.anim.translate);
is this the best way or can I set this up somewhere for my whole app? 这是最好的方法,还是可以在整个应用程序的某个地方进行设置? And also, if I use this animation, the new Activity "rotates" into the screen very nice but the background gets black. 而且,如果我使用此动画,新的“活动”会非常漂亮地“旋转”到屏幕中,但背景会变黑。 (I think because of the translate animation?!) How can I set up my own Background? (我认为是因为翻译动画?!)如何设置自己的背景?
the code from the translate animation is: 翻译动画的代码为:
<?xml version="1.0" encoding="utf-8"?>
<translate>
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="200%"
android:toXDelta="0%"
android:fromYDelta="200%"
android:toYDelta="0%"
android:duration="1000"
android:zAdjustment="top" />
and the rotate animation: 和旋转动画:
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="0"
android:pivotX="-5%"
android:pivotY="5%p"
android:duration="1000" />
The current way you have it: 您目前拥有的方式:
overridePendingTransition(R.anim.rotate, R.anim.translate);
The best way to set this is either via an abstract Activity
or composition which is more to do with programming practice than Android specifically. 最好的设置方法是通过抽象Activity
或组合 ,这与编程实践有关,而与Android无关。
The short being: 简短的是:
public abstract BaseActivity extends FragmentActivity{
@Override
protected onCreate(Bundle savedInstance){
overridePendingTransition(R.anim.rotate, R.anim.translate);
}
}
Then your concrete Activity
extends this. 然后,您的具体Activity
将对此进行扩展。
public class MyActivity extends BaseActivity{}
So the current setup means that your New Activity
will Rotate in , and your old activity (should) translate out . 所以,当前的设置意味着你的新Activity
将在旋转,而旧的活动(应该)翻译出来 。
Seen as your translating your old activity out (not in) the animation is a bit wrong. 视您将旧活动翻译成(不是)翻译动画有点错误。 A correct translate animation for translating out would be something like: 用于翻译的正确翻译动画如下所示:
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="1000" />
Which will translate the exiting activity from centre screen to slide to the right. 这会将当前活动从中心屏幕转换为向右滑动。
Also ignore the zAdjustment
, by default your new activity starts on top of the old one, you dont want to leave the old on top. 也请忽略zAdjustment
,默认情况下,您的新活动从旧活动开始,您不想将旧活动放在最前面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.