Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7671651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:06:29+00:00 2026-05-31T16:06:29+00:00

when switching between two activities, screen slides between right to left. When I press

  • 0

when switching between two activities, screen slides between right to left. When I press back key, screen slides from right to left. Is it a way that when I press back key from an activity to change screen sliding direction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:06:30+00:00Added an answer on May 31, 2026 at 4:06 pm

    Danny’s solution could be made to work but it is overly complicated. The key method you want to learn about is overridePendingTransition().

    Here is main activity that I mocked up to use it. I made it transition vertically just to show that you can make transformations in any direction you like:

    package com.superliminal.test;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class ScreenTransitionTest extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Button btnForwards = (Button) findViewById(R.id.btnForwards);
            btnForwards.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Activity currentActivity = (Activity) v.getContext();
                    Intent i = new Intent(currentActivity, NewScreen.class);
                    // Tell the new activity how return when finished.
                    i.putExtra("anim id in", R.anim.down_in);
                    i.putExtra("anim id out", R.anim.down_out);
                    currentActivity.startActivity(i);
                    // This makes the new screen slide up as it fades in
                    // while the current screen slides up as it fades out.
                    overridePendingTransition(R.anim.up_in, R.anim.up_out);
                }
            });
        }
    }
    

    Here is the implementation of the new screen:

    package com.superliminal.test;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    public class NewScreen extends Activity {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.new_screen);
        }
    
        @Override
        public void onBackPressed() {
            this.finish();
            // Use exiting animations specified by the parent activity if given
            // Translate left if not specified.
            overridePendingTransition(
                getIntent().getIntExtra("anim id in", R.anim.left_in),
                getIntent().getIntExtra("anim id out", R.anim.left_out));
        }
    }
    

    Your layout files can be anything you like. You don’t need a wrapper layer. Here is my main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#990000" >
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Main Activity" />
        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/btnForwards"
            android:text="Forward" />
    </LinearLayout>
    

    And here is my new_screen.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#009900" >
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="New Screen. Use back button to return." />
    </RelativeLayout>
    

    The only other things you need are animation XML files that you put in the res/anim folder.

    up_in.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate android:fromYDelta="-100%p" android:toYDelta="0" android:duration="1000"/>
        <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000" />
    </set>
    

    up_out.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="1000"/>
        <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="1000" />
    </set>
    

    down_in.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="1000"/>
        <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000" />
    </set>
    

    down_out.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate android:fromYDelta="0" android:toYDelta="-100%p" android:duration="1000"/>
        <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="1000" />
    </set>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program switches between two Activities that each inflate a derived GLSurfaceView that uses
My application is running out of memory which switching between two activities. The first
When switching between windows in my full screen WPF app, if it is the
I've tried a few Asus Ones, and found that even switching between multiple windows
Does switching activities in Android start a fresh JVM? It seems like each activity
When Switching between two view controllers, what's the difference between addSubView or using a
I have an iphone application that crashes when I switch between two of the
I have two apps that I want to be able to switch between without
I have an app with two screens, and buttons that switch between them. One
I must admit, that usually I haven't bothered switching between the Debug and Release

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.