Reputation: 742
I'm developing an application which involves transition between activities. Using override pending transition i succeed in that but the animation between activities only support in some of devices by default. But some of the devices manually has to set animation in settings.Now the question is using code this is possible or not?
Any sample code or links really appreciable
Thanks in advance.
Upvotes: 0
Views: 3173
Reputation: 10717
We can make a animation between activities with this steps:
First step, in res we create directory, which name is anim, after that. In this directory, We create 4 files:
go_in.xml
<translate
android:duration="700"
android:fromYDelta="100%"
android:toYDelta="0%"/>
go_out.xml
<scale android:duration="700"
android:fromXScale="100%"
android:fromYScale="100%"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="70%"
android:toYScale="70%"/>
back_in.xml
<scale android:duration="700"
android:fromXScale="70%"
android:fromYScale="70%"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="100%"
android:toYScale="100%"/>
back_out.xml
<translate
android:duration="700"
android:fromYDelta="0%"
android:toYDelta="100%"/>
After that We need two activities. FirstActivity
package com.thedeveloperworldisyours.gmailanimation;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void goTo(View view) {
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
}
}
this is layout activity_first.xml:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:onClick="goTo"
android:text="@string/activity_main_go" />
Finally in your Second Activity
package com.thedeveloperworldisyours.gmailanimation;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class SecondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
overridePendingTransition(R.anim.go_in, R.anim.go_out);
}
public void back(View view) {
finishMyActivity();
}
@Override
public void onBackPressed() {
finishMyActivity();
}
public void finishMyActivity() {
finish();
overridePendingTransition(R.anim.back_in, R.anim.back_out);
}
}
This is layout activity_second.xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:onClick="back"
android:text="@string/activity_second_back" />
You can see these examples in GmailAnimation or LopeAnimations. Also you can see more in this Blog.
Upvotes: 1
Reputation: 13129
You don't really have control over Activity animations apart from overridePendingTransitions
which is API 5 onwards, which in all honest covers all devices (set your min API to 7/8 that covers 94%+ of devices).
If a specific device overrides the transition type then you can't do much about that, but what you normally find is that its for the default animation.
Calling overridePendingTransition()
in onCreate()
will override what ever they device does by default.
Upvotes: 0