45

In My Application i am going to set the alpha after one animation. As like:

hideMenu = AnimationUtils.loadAnimation( getApplication(), R.anim.menu_layout_hide);
 menuLayout.startAnimation(hideMenu);
 menuLayout.setVisibility(View.GONE);

But i want to set the delay of 1 Sec before the Alpha set th the View. as Because of that i am not able to see the Animation of that layout. So How it is possibe ?

Thanks.

Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188

5 Answers5

87

In your animation xml file you can use android:startOffset attribute:

android:startOffset int. The amount of milliseconds the animation delays after start() is called.
Dmytro Danylyk
  • 19,684
  • 11
  • 62
  • 68
80

Can't you use the

android:startOffset int. The amount of milliseconds the animation delays after start() is called.

in your animation xml?

See the animation resource documentation.

likebobby
  • 1,379
  • 2
  • 14
  • 21
29

Suppose you are using the view .animate() method, you can set the start offset:

view.animate().x(100)
              .setDuration(5000)
              .setStartDelay(1000);
weston
  • 54,145
  • 21
  • 145
  • 203
10

Handler is a good technique to achieve this.

new Handler().postDelayed(new Runnable()
{
   @Override
   public void run()
   {
     view.startAnimation(animation);
   }
}, 1000);
Kanagalingam
  • 2,096
  • 5
  • 23
  • 40
8

In your case you can simply do like this

hideMenu = AnimationUtils.loadAnimation( getApplication(), R.anim.menu_layout_hide);

hideMenu.setStartOffset(1000);

 menuLayout.startAnimation(hideMenu);
 menuLayout.setVisibility(View.GONE);

In this case you can control dynamically value of the start time from the activity

Observer
  • 3,506
  • 1
  • 16
  • 32