禁用 android 应用中的所有动画
Disabling all animations in an android app
我想禁用在我的 android 应用程序中启动新 activity 时发生的所有动画(针对所有活动)。有没有办法一劳永逸地实现这一目标?或者我应该去每个 activity 并使用 Intent.FLAG_ACTIVITY_NO_ANIMATION 或 overridePendingTransition 或两者都使用?
您可以根据需要使用样式:
<style name="noAnimTheme" parent="android:Theme">
<item name="android:windowAnimationStyle">@null</item>
</style>
并为您的 activity 设置它们:
<activity android:name=".ui.ArticlesActivity" android:theme="@style/noAnimTheme">
</activity>
如果那是你的意思,请告诉我...
感谢@Santosh
当我构建我的应用程序时,我只使用了一个 activity。在 activity 上有 4 个自定义视图。每个自定义视图代表另一个 "Activity" 它不是真的 activity...我玩的自定义视图很少所以每个都是另一个 window...
这是带有动画的代码(*** 如果您不想要动画,请跳过此代码到下面的下一个 goToRegistrationPage()
。):
//This code change the view so that the register form will appear. instead of changing activity with animation.
public void goToRegistrationPage()
{
Animation animationRightX1 = AnimationUtils.loadAnimation(this, R.anim.translate_right_x1);
//animationRightX1.
Animation animationRightX2 = AnimationUtils.loadAnimation(this, R.anim.translate_right_x2);
Animation animationRightX3 = AnimationUtils.loadAnimation(this, R.anim.translate_right_x3);
final int width = this.getWindowManager().getDefaultDisplay().getWidth();
layout.MainView.setVisibility(View.GONE);
layout.MainLogin.startAnimation(animationRightX1);
layout.MainRegister.startAnimation(animationRightX1);
animationRightX1.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
layout.layoutScroll.scrollTo((width*2), 0);
layout.MainView.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
这里是没有动画的代码(这是你需要的):
//This code change the view so that the register form will appear. instead of changing activity
//Go to the registration form from the main view.
public void goToRegistrationPageFromMainView()
{
final int width = this.getWindowManager().getDefaultDisplay().getWidth();
layout.layoutScroll.scrollTo((width*2), 0); // its width*2 because there is the "some other view" so it need to go 2 times width to the right side...
}
所以基本上你在这里做的是滚动 windows 宽度像素。
layoutscroll
就是图中的粉色
layout
是我创建的一个 class 来存储所有布局...您可以根据个人喜好 this.layoutscroll...
.
- 主视图、其他视图和注册表是扩展线性布局的自定义视图...您可以附加到每个 XML 带有线性布局充气器的文件...
- 当然你让滚动视图不可滚动....
我想禁用在我的 android 应用程序中启动新 activity 时发生的所有动画(针对所有活动)。有没有办法一劳永逸地实现这一目标?或者我应该去每个 activity 并使用 Intent.FLAG_ACTIVITY_NO_ANIMATION 或 overridePendingTransition 或两者都使用?
您可以根据需要使用样式:
<style name="noAnimTheme" parent="android:Theme">
<item name="android:windowAnimationStyle">@null</item>
</style>
并为您的 activity 设置它们:
<activity android:name=".ui.ArticlesActivity" android:theme="@style/noAnimTheme">
</activity>
如果那是你的意思,请告诉我...
感谢@Santosh
当我构建我的应用程序时,我只使用了一个 activity。在 activity 上有 4 个自定义视图。每个自定义视图代表另一个 "Activity" 它不是真的 activity...我玩的自定义视图很少所以每个都是另一个 window...
这是带有动画的代码(*** 如果您不想要动画,请跳过此代码到下面的下一个 goToRegistrationPage()
。):
//This code change the view so that the register form will appear. instead of changing activity with animation.
public void goToRegistrationPage()
{
Animation animationRightX1 = AnimationUtils.loadAnimation(this, R.anim.translate_right_x1);
//animationRightX1.
Animation animationRightX2 = AnimationUtils.loadAnimation(this, R.anim.translate_right_x2);
Animation animationRightX3 = AnimationUtils.loadAnimation(this, R.anim.translate_right_x3);
final int width = this.getWindowManager().getDefaultDisplay().getWidth();
layout.MainView.setVisibility(View.GONE);
layout.MainLogin.startAnimation(animationRightX1);
layout.MainRegister.startAnimation(animationRightX1);
animationRightX1.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
layout.layoutScroll.scrollTo((width*2), 0);
layout.MainView.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
这里是没有动画的代码(这是你需要的):
//This code change the view so that the register form will appear. instead of changing activity
//Go to the registration form from the main view.
public void goToRegistrationPageFromMainView()
{
final int width = this.getWindowManager().getDefaultDisplay().getWidth();
layout.layoutScroll.scrollTo((width*2), 0); // its width*2 because there is the "some other view" so it need to go 2 times width to the right side...
}
所以基本上你在这里做的是滚动 windows 宽度像素。
layoutscroll
就是图中的粉色
layout
是我创建的一个 class 来存储所有布局...您可以根据个人喜好 this.layoutscroll...
.
- 主视图、其他视图和注册表是扩展线性布局的自定义视图...您可以附加到每个 XML 带有线性布局充气器的文件...
- 当然你让滚动视图不可滚动....