3D transition animation between Activities

11 replies [Last post]
paller's picture
Offline
Joined: 11 Apr 2010
Points: 191
0
0

I have got a question in this post on the Sfonge site whether it is possible to create a 3D transition effect between two Activities. There is a sample program that does it among the API Demos but this program plays the transition effect between two views of the same Activity. The adaptation to do the same between two activities is not very complicated but has some tricks, that's why I decided to publish this example program.

The example program is attached to this post. You have to be logged in to Sfonge site to access it.

First and foremost, I unashamedly stole the custom 3D animation from the API Demos application, that's what you find in Rotate3dAnimation.java. It is invoked in the landing Activity (Activity3dTransitionActivity) when the user initates transition to the second Activity (Screen2Activity) using the menu. The trick here is to attach an animation listener to the 3D animation object, start the animation in the outgoing Activity and only invoke startActivity() when the animation finishes. Note the overridePendingTransition( 0,0 ) invocation; this ensures that the system itself will not play any activity transition animation.

The incoming Screen2Activity seems simple but there is hidden gem here too. Observe that the top layout of the activity (in screen2.xml) is not a stock LinearLayout but a descendant (aexp.activity3dtransition.AnimatedLinearLayout). Overriding onMeasure() in this subclass makes sure that the incoming animation is started only after the elements of the layout (a single TextView here) have beenlaid out.

Attached file: 
Rupal Thanki's picture
Offline
Joined: 2 Apr 2012
Points: 35
have you saw the Go SMS pro?

have you saw the Go SMS pro? https://play.google.com/store/apps/details?id=com.jb.gosms&hl=en I want same as like Support GESTURE, left/right slip, many transition effect. like 2 App Screenshots. plz see and how to implement that effect.

Rupal Thanki's picture
Offline
Joined: 2 Apr 2012
Points: 35
and Apply Gesture event on

and Apply Gesture event on Activity

paller's picture
Offline
Joined: 11 Apr 2010
Points: 191
GestureDetector

Can't you use the example described in this post? The only difference is that in MyGestureDetector you don't do a view flip but invoke a new Activity.

Rupal Thanki's picture
Offline
Joined: 2 Apr 2012
Points: 35
i have to apply 3D Cube

i have to apply 3D Cube transition animation between two activity. this animation is not like 3D Cube on gesture event. do you have any idea about the 3d cube transition animation?

paller's picture
Offline
Joined: 11 Apr 2010
Points: 191
Cube animation

Check out Rotate3dAnimation.java, it was actually copied from the API Demos sample. It uses a Camera (not the hardware camera but  an object of the 2D graphics toolkit) to take the views of the layout from different angles. What it does now is a flip. Using the same mechanism, you can implement the cube too. The only problem is that for a cube animation you need both the outgoing and the incoming layout which makes nice separation into standalone activities sort of hard to do (the animation must work on both the incoming and the outgoing layout at the same time).

Rupal Thanki's picture
Offline
Joined: 2 Apr 2012
Points: 35
R u busy?

R u busy?

Rupal Thanki's picture
Offline
Joined: 2 Apr 2012
Points: 35
give any idea how to do like

give any idea how to do like the animation must work on both the incoming and the outgoing layout at the same time. R u busy ?

Rupal Thanki's picture
Offline
Joined: 2 Apr 2012
Points: 35
give any idea how to do like

give any idea how to do like that

Rupal Thanki's picture
Offline
Joined: 2 Apr 2012
Points: 35
give any idea how to do like

give any idea how to do like the animation must work on both the incoming and the outgoing layout at the same time.

paller's picture
Offline
Joined: 11 Apr 2010
Points: 191
Incoming and outgoing layout

The key is that any View which is part of the current layout can be animated. This means that the incoming layout must also be included in the outgoing layout. E.g. in screen1.xml in the example program:

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

<TextView
android:id="@+id/screen1_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textSize="40dp"
android:text="@string/screen1" />

<TextView
android:id="@+id/screen2_container_in_screen1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textSize="40dp"
android:text="@string/screen2"
android:visibility="invisible" />

</FrameLayout>
The second TextView (with the id of screen2_container_in_screen1) is meant to represent the incoming layout and is the same as the content of screen2.xml. You can make this more elegant by including the incoming layout.
Now the only thing to do is to animate both layouts when the animation starts. I changed the example program like this:

private void gotoScreen2() {
View g = (View)findViewById( R.id.screen1_container);
applyRotation( g,0,90, new GotoNextActivity());
View g2 = (View)findViewById( R.id.screen2_container_in_screen1);
g2.setVisibility( View.VISIBLE);
applyRotation( g2,90,0, null);
}
 
This does not do exactly what you want but makes the point how the outgoing and incoming layout can be on the screen at the same time and can be subject to different animation.
Eventually the second Activity is started after the animation. As we have already played the animation belonging to the incoming layout, no animation is needed when the second Activity starts.
 
 

Rupal Thanki's picture
Offline
Joined: 2 Apr 2012
Points: 35
Thank u....

Thank u....