3

There are two Activities.

Activity A is a full-screen Activity (status bar hidden), using getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Activity B is a normal Activity (status bar visible).

I need to navigate between Activity A and Activity B.

The problem is that there is a jerking motion while going from A to B as the status bar becomes visible and the activity resizes.

Any idea how I can ensure a smooth transition from one to Activity to the other?

Also, I am using slide-in and slide-out animations for transition between activities.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Swayam
  • 16,294
  • 14
  • 64
  • 102

2 Answers2

2

You can simply use animation while switching activities,

        startActivity(new Intent(FirstActivity.this, SecondActivity.class));
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

EDIT :

Replace following piece of block

<translate         
 android:duration="300"
 android:fromXDelta="100%"
 android:fromYDelta="0%"
 android:toXDelta="0%"
 android:toYDelta="0%">

with this one

<translate         
 android:duration="300"
 android:fromXDelta="100%"
 android:fromYDelta="0%"
 android:toXDelta="0%"
 android:toYDelta="0%">

<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />

Note:

whole code should be looking like this,

    <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate         
     android:duration="300"
     android:fromXDelta="100%"
     android:fromYDelta="0%"
     android:toXDelta="0%"
     android:toYDelta="0%">

    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />

</set>

Optional Way: (Reference: article)

Instead of adding alpha to your existing animations, try this way if it helps,

Replace

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,     WindowManager.LayoutParams.FLAG_FULLSCREEN);

with

    WindowManager.LayoutParams attributes = getWindow().getAttributes();
    attributes.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |   WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
    getWindow().setAttributes(attributes);
Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57
  • Ah, I wish I could do that. I am already using my custom animation for transition, which is basically a slide-in and slide-out animation. – Swayam Jul 30 '14 at 09:14
  • @Swayam: you can use both effects.can you plz put the code of those animations? – Mehul Joisar Jul 30 '14 at 09:24
  • Oh wow. That would be really great. I am using something in the lines of `` – Swayam Jul 30 '14 at 09:28
  • Thanks much! Lemme check and get back to you. Also, is there no way to do this with out the fading effect? I mean, I use a standard set of animations in the app. I am not sure whether it would be desirable to have a different animation for this case. – Swayam Jul 30 '14 at 09:36
  • @Swayam: AFAIK, there is no way because it is not jerking due to your app, it should be handled smoothly by Android OS itself while showing or hiding status bar. Unfortunately, Android lacks such things,so developers have to use such workarounds. – Mehul Joisar Jul 30 '14 at 09:41
  • Yes, I agree that it is not due to my app. I think Android is not being to do the Activity resizing properly. But, then again, any other workarounds without affecting the alpha value? I mean, like I said, the animations throughout the app should be consistent. I can't introduce a new animation for this transition, because otherwise in the rest of the app, I am using the existing animations. – Swayam Jul 30 '14 at 09:44
  • @Swayam: jerk is visible because screen has been resized without smoothness, we can't change that code of resizing.all we can do is to make the screen to be fade while resizing is in progress, and alpha is nothing but fade in animation.I guess there is no harm in using it even throughout the app. – Mehul Joisar Jul 30 '14 at 09:56
  • Yes, I agree. Let me see if there is anything else possible. Thank you very much for your inputs. +1 :) – Swayam Jul 30 '14 at 10:00
1

I use Theme.AppCompat.Light.NoActionBar in my styles for the Activity which I want to show as fullscreen and then the below as rightly pointed out by @MehulJoisar

WindowManager.LayoutParams attributes = getWindow().getAttributes();
    attributes.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |   WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; 
    getWindow().setAttributes(attributes);

Happy Coding :)

Atul O Holic
  • 6,692
  • 4
  • 39
  • 74