Reputation: 23
The animation on the first activity does not work when I use startActivity
and I don't know it's strange.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
ImageView img = (ImageView) findViewById(R.id.splash);
img.animate().scaleX(0.6f).scaleY(0.6f).rotation(1080f).setDuration(2000);
Intent intent = new Intent(getApplicationContext(), NextActivity.class);
startActivity(intent);
}
}
Upvotes: 0
Views: 163
Reputation: 6821
@Zakaria Ait Ouchrif,
You can use the method of Activity overridePendingTransition() with two xml of in and out Animation.
You can define simple transition animations in an XML resource file.
Also you can refer this tutorial for same.
Upvotes: 0
Reputation: 1271
Use this.
private Handler handlerImage;
private Runnable runnableImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
ImageView img= (ImageView) findViewById(R.id.splash);
img.animate().scaleX(0.6f).scaleY(0.6f).rotation(1080f).setDuration(2000);
handlerImage = new Handler();
runnableImage = new Runnable() {
@Override
public void run() {
Intent intent=new Intent(getApplicationContext(),NextActivity.class);
startActivity(intent);
}
};
handlerImage.postDelayed(runnableImage, 3000);
}
@Override
protected void onDestroy() {
super.onDestroy();
if (handlerImage != null) {
handlerImage.removeCallbacks(runnableImage);
}
}
Upvotes: 1
Reputation: 949
Check this,
Intent intent=new Intent(this,NextActivity.class);
startActivity(intent);
Upvotes: 0
Reputation: 1694
I hope you are trying to show a scale and rotation animation of your APP logo for sometime and then trying to launch Another Activity.
Since you are starting Another activity ,Before Starting Animation on the Imageview, ActivityManager will switch to the Next Animation, and hence you are not able to see the Animation, Solution is to set an Animationlistner to the ViewPropertyAnimator object given to ImageView and Start the main Activity on onAnimationEnd() callback.
code snippet is given below:
img.animate().scaleX(0.6f).scaleY(0.6f).rotation(1080f).setDuration(2000).setListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animator animation) {
Intent intent=new Intent(getApplicationContext(),NextActivity.class);
startActivity(intent);
}
@Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
Upvotes: 0