Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

animation in android

Tags:

android

I had an activity (say homeActivity) and when I start a new activity(say nextActivity) from my homeactivity i would like to give it an animation effect like appearing it from the bottom. Is it possible in android?

like image 776
tvm_pgmr Avatar asked Mar 05 '11 09:03

tvm_pgmr


3 Answers

after call to startActivity, make call to overridePendingTransition with id's of xml defined animations, one for exiting activity, one for entering. See docs for this method here

like image 83
Nikolay Ivanov Avatar answered Oct 19 '22 18:10

Nikolay Ivanov


You can prevent the default animation (Slide in from the right) with the Intent.FLAG_ACTIVITY_NO_ANIMATION flag in your intent.

i.e.:

Intent myIntent = new Intent(context, MyActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
context.startActivity(myIntent);

then in your Activity you simply have to specify your own animation.

like image 40
Umesh K Avatar answered Oct 19 '22 19:10

Umesh K


TopListActivity topList;
Vector<BitmapDrawable> images;
int count = 0;
public AnimationAlphaTimer(TopListActivity _topList)
{
  this.topList = _topList;

  this.images = new Vector<BitmapDrawable>();
  for (int i = 0; ; i++) {
  // LOAD IMAGES HERE
  }

  if (this.images.size() > 0) {
    this.topList.slide_0.setBackgroundDrawable(this.images.get(0));

    if (this.images.size() > 1) {
      this.topList.slide_1.setBackgroundDrawable(this.images.get(1));
    }
  }

  this.count = 1;
}

public void launch()
{
  if (this.images.size() >= 2) {
    (new Timer(false)).schedule(this, 100);
  }
}

@Override
public void run()
{
  this.doit();
  this.cancel();
}

private void doit()
{
  if ((this.count % 2) == 0) {
    AlphaAnimation animation = new AlphaAnimation(1.0f, 0.0f);
    animation.setStartOffset(3000);
    animation.setDuration(3000);
    animation.setFillAfter(true);
    animation.setAnimationListener(this);

    this.topList.slide_1.startAnimation(animation);
  } else {
    AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setStartOffset(3000);
    animation.setDuration(3000);
    animation.setFillAfter(true);
    animation.setAnimationListener(this);

    this.topList.slide_1.startAnimation(animation);
  }
}

public void onAnimationEnd(Animation animation)
{
  if ((this.count % 2) == 0) {
    this.topList.slide_1.setBackgroundDrawable(
      this.images.get((this.count + 1) % (this.images.size()))
    );
  } else {
    this.topList.slide_0.setBackgroundDrawable(
      this.images.get((this.count + 1) % (this.images.size()))
    );
  }

  this.count++;
  this.doit();
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation)  {
}}

try this i think it will work.

like image 1
user1008590 Avatar answered Oct 19 '22 19:10

user1008590