2

I want to disable all the animations that happen when launching a new activity in my android app (for all the activities). Is there a way to achieve this once and for all? Or should I go to each and every activity and use Intent.FLAG_ACTIVITY_NO_ANIMATION or overridePendingTransition or both?

bighi
  • 247
  • 3
  • 13
  • 1
    If you want to debug your issue. Then please try to switch off the android animation in developer options. If that does not helps please follow http://stackoverflow.com/questions/6972295/switching-activities-without-animation – Sam Nov 25 '15 at 18:56

1 Answers1

2

You can use style if you want:

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

And set them for your activity:

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

Let me know if thats what you meant...

Credit to @Santosh https://stackoverflow.com/a/9312957/3180983

When I built my app, I used only one activity. On the activity there was 4 Custom views. Each custom view represent another "Activity" its not really activity... Im playing with few custom view so each one is another window...

Here is the code with animation (*** IF you don't want animation SKIP THIS CODE to the next goToRegistrationPage() down below.):

//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) {

            }
        });
    }

And here is the code without the animation (This is what you need):

//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...
        }

So basically what you do here is scrolling windows with width amount of pixels.

layoutscroll is the pink color in the picture.

layout is a class which I created to store all the layouts... its a personal preference you could do this.layoutscroll....

How it looks like

  • Mainview, other view, and registration form are custom views that extending linearlayout... you can attach to each one of them XML file with linear layout inflater...
    • Ofcorse that you make the scroll view unscrollable....
Community
  • 1
  • 1
BananaBuisness
  • 339
  • 2
  • 18
  • Still I have to do this for each and every activity separately right? – bighi Nov 26 '15 at 14:25
  • When I do projects I don't change activities I do one activity and every time I want to "change activity" I make one custom view disappear and an other will appear... – BananaBuisness Nov 26 '15 at 14:29
  • 1
    So let's say I have 2 custom views what I do is I play with the invisibility. Not only that you can do it without animation, if you do it with animation it will be much faster and custom animations... – BananaBuisness Nov 26 '15 at 14:31
  • Here, I edited the code... this is how you can change views without the change activity animation... – BananaBuisness Nov 26 '15 at 17:48