How do I Change the default animation when changing activity?

MrCloister picture MrCloister · Feb 17, 2011 · Viewed 28k times · Source

Hello I have an application which I can touch to scroll across several screens like the Android Homescreen app.

I have now managed to add a button on each page which changes from this to a new activity, but the scrolling is left to right and I want it to scroll down when the button is clicked but I can't figure out how to do it.

(This is probably a very noob question - sorry for that.)

Here is my main.java file

public class main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button onebutton = (Button)findViewById(R.id.soundsone);
        onebutton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        Intent i = new Intent(main.this, series1button.class);
        startActivity(i);

    }
});


        Button twobutton = (Button)findViewById(R.id.soundstwo);
        twobutton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        Intent i = new Intent(main.this, series2button.class);
        startActivity(i);

    }
});  
        Button threebutton = (Button)findViewById(R.id.soundsthree);
        threebutton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        Intent i = new Intent(main.this, series3button.class);
        startActivity(i);

    }
});        Button fourbutton = (Button)findViewById(R.id.soundsfour);
        fourbutton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        Intent i = new Intent(main.this, series4button.class);
        startActivity(i);

    }
});        Button fivebutton = (Button)findViewById(R.id.soundsfive);
        fivebutton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        Intent i = new Intent(main.this, series5button.class);
        startActivity(i);

    }
});        Button sixbutton = (Button)findViewById(R.id.soundssix);
        sixbutton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        Intent i = new Intent(main.this, series6button.class);
        startActivity(i);

    }
});        Button sevenbutton = (Button)findViewById(R.id.soundsseven);
        sevenbutton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        Intent i = new Intent(main.this, series7button.class);
        startActivity(i);

    }
});        Button eightbutton = (Button)findViewById(R.id.soundseight);
        eightbutton.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {
        Intent i = new Intent(main.this, series8button.class);
        startActivity(i);

    }
});
    }
}

Answer

ZelluX picture ZelluX · Feb 25, 2011

You may refer to the example in apidemos's directory, which uses overridePendingTransition to show custom animation. Also another post related to this topic: Can I change the Android startActivity() transition animation?