1

I have used overridePendingTransition()already but it is used to open an activity with the given transition not an app.

Moreover it works only when you are having an intent on clicking on a button, it won't work if use overridePendingTransition() in onCreate()

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Intent i = new Intent(Main2Activity.this,MainActivity.class);
        startActivity(i);
        overridePendingTransition(R.anim.slide_in_up,R.anim.slide_out_up);
    }
Edson Menegatti
  • 4,006
  • 2
  • 25
  • 40
user3542307
  • 139
  • 1
  • 8

1 Answers1

1

before setContentView use following code :

overridePendingTransition(R.anim.slide_in_from_bottom, R.anim.fade_out);

and in your finish() use following code :

@Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.fade_in, R.anim.slide_out_back_to_bottom);
    }

and create anim folder and put these files :

slide_in_from_bottom:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:zAdjustment="top">
    <translate
            android:duration="400"
            android:fromYDelta="100%p"
            android:toYDelta="0%p"
            >
    </translate>
    <alpha
            android:fromAlpha="0.8"
            android:toAlpha="1.0"
            android:duration="400"
            />
</set>

slide_out_back_to_bottom:

 <set xmlns:android="http://schemas.android.com/apk/res/android"
         android:zAdjustment="top">
        <translate
                android:duration="400"
                android:fromYDelta="0%p"
                android:toYDelta="100%p"
                >
        </translate>
        <alpha
                android:fromAlpha="1.0"
                android:toAlpha="0.8"
                android:duration="400"
                />
    </set>

fade_in:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:zAdjustment="bottom">
    <alpha
            android:fromAlpha="0.0"
            android:toAlpha="1.0"
            android:duration="300"
            />
</set>

fade_out:

<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:zAdjustment="bottom">
    <alpha
            android:fromAlpha="1.0"
            android:toAlpha="0.0"
            android:duration="200"
            />
</set>

complete implementation can be found here.

Amir
  • 16,067
  • 10
  • 80
  • 119
  • Are u sure it will work for launching the android app from bottom to top ? – user3542307 May 28 '16 at 13:34
  • Yes! I'm using this in one of my project too. also as you see I'm using Transition from 0% to 100% , this is exactly what you want. I also a bit fade_in/fade_out to be better. – Amir May 28 '16 at 13:36
  • is it correct :( if not can u share ur apk on drive or whereever – user3542307 May 28 '16 at 13:39
  • `public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up); setContentView(R.layout.activity_main); } @Override public void finish() { super.finish(); overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up); } }` – user3542307 May 28 '16 at 13:40
  • i have wasted my 5 hours in finding the solution, but the app is not launching from the bottom please help – user3542307 May 28 '16 at 13:42
  • wait 5min to push it in Github :) – Amir May 28 '16 at 13:45
  • thanks mate but the mainactivity is not showing any transition :( – user3542307 Jun 02 '16 at 16:56
  • @user3542307 Yeah. I use transition for **DetailsActivity** you can apply same rule to **MainActivity**. – Amir Jun 02 '16 at 17:20