【问题标题】:Disabling all animations in an android app禁用android应用程序中的所有动画
【发布时间】:2015-11-25 18:52:44
【问题描述】:

我想禁用在我的 android 应用中启动新活动时发生的所有动画(对于所有活动)。有没有办法一劳永逸地实现这一目标?还是我应该去每个活动并使用 Intent.FLAG_ACTIVITY_NO_ANIMATION 或 overridePendingTransition 或两者兼而有之?

【问题讨论】:

标签: android android-animation android-transitions


【解决方案1】:

您可以根据需要使用样式:

<style name="noAnimTheme" parent="android:Theme">
   <item name="android:windowAnimationStyle">@null</item>
</style>

并为您的活动设置它们:

 <activity android:name=".ui.ArticlesActivity" android:theme="@style/noAnimTheme">
    </activity>

如果你是这个意思,请告诉我...

感谢@Santosh https://stackoverflow.com/a/9312957/3180983

当我构建我的应用程序时,我只使用了一项活动。在活动中有 4 个自定义视图。每个自定义视图都代表另一个“活动”,它不是真正的活动......我玩的自定义视图很少,所以每个都是另一个窗口......

这是带有动画的代码(*** 如果您不想要动画,请跳过此代码到下面的下一个 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...
        }

所以基本上你在这里所做的是滚动具有像素宽度的窗口。

layoutscroll是图片中的粉红色。

layout 是我创建的用于存储所有布局的类...您可以根据个人喜好设置this.layoutscroll...

  • 主视图、其他视图和注册表单是扩展线性布局的自定义视图...您可以使用线性布局充气器将 XML 文件附加到每个视图...
    • Ofcorse 使滚动视图不可滚动....

【讨论】:

  • 我仍然必须为每项活动分别执行此操作吗?
  • 当我做项目时,我不改变活动我只做一个活动,每次我想“改变活动”时,我都会让一个自定义视图消失,另一个会出现......
  • 假设我有 2 个自定义视图,我所做的就是玩隐形。不仅可以不使用动画,而且如果使用动画,速度会更快,而且自定义动画...
  • 在这里,我编辑了代码...这就是在不更改活动动画的情况下更改视图的方法...
猜你喜欢
  • 2021-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-11
  • 1970-01-01
  • 2020-04-04
  • 1970-01-01
  • 2018-08-06
相关资源
最近更新 更多