4

actually I want to rotate or flip the screen by clicking on button from one activity to another: like this

thanks in advance.

SpeedBirdNine
  • 4,610
  • 11
  • 49
  • 67
ManjotSingh
  • 713
  • 7
  • 20

3 Answers3

3

You can override the transition between Activities doing this:

Button btn = (Button)findViewById(R.id.myBtn);

btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            startActivity(new Intent(ActualActivity.this, 
                    TargetActivity.class));
            overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
        }
    });

Where slide_in_up and slide_out_up are your custom animations, saved in res/anim. Here there are some code examples:

slide_in_up:

<?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="300"/>
</set>

slide_out_up:

<?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="300"/>
</set>

This example will move your activity from top to bottom. You can modify your anim files to obtain different animations.

Stefano Ortisi
  • 5,288
  • 3
  • 33
  • 41
  • But how with an XML transition can you achieve a 3D flip? – Goofyahead Jul 02 '12 at 08:15
  • 1
    Xml way: http://stackoverflow.com/questions/8570906/android-flip-animation-using-xml-for-animation-in-android - Programmatically way: http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html – Stefano Ortisi Jul 02 '12 at 08:18
  • its moving from one screen to onother but i want when i click on one screen then screen must be rotate at 180 degree – ManjotSingh Jul 02 '12 at 09:55
1

You can find you answer here: Activity transition in Android

Two options:

  1. Read this tutorial http://developerlife.com/tutorials/?p=343
  2. Tell the second activity (the one you open using the button) what animation to show on create.

Like this:

@Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        getWindow().setWindowAnimations(ANIMATION);

        ...

    }
Community
  • 1
  • 1
Lior Iluz
  • 26,213
  • 16
  • 65
  • 114
  • can you set an animation that is defined in a class extending animation? If not its not possible to make a 3D rotation in XML transition, isnt it? – Goofyahead Jul 02 '12 at 08:17
  • @Goofyahead 3D is a somewhat problematic definition for this but basically you can define a "3D" effect in XML. There's an example in the API Demos application. – Lior Iluz Jul 02 '12 at 08:30
  • how to define "3D"effect in XML?? – ManjotSingh Jul 02 '12 at 09:53
1

The link that @abhy provided is the one that we all followed once :)

But its not going to work to change from one activity to another, what i did to achieve that behaviour its to obtain the bitmap of the activity im in and the one that im heading to, make this transition and when its finish make the startactivity overriding the pending transition with no effect.

I dont think that is a great approach and i will love to see if someone has a better idea :)

Regards,

Goofyahead
  • 5,874
  • 6
  • 29
  • 33
  • This also seems to be a nice and simple alternative which can be used to achieve flip animations. – abhy Jul 02 '12 at 09:16