Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a SlidingDrawer be animated?

I try to open/close my slidingdrawer with animateOpen() and animateClose(), but it seems it opens and closes instantaneously, like open() and close(). What's wrong?

I've seen that SlidingDrawer can't be customized (can't be animated with custom animation for instance, even not with custom open/close duration). Do I have to copy SlidingDrawer's code just to change the animation duration?

Thanks

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.home);        

    // Open and close banner
    final SlidingDrawer banner = (SlidingDrawer) findViewById(R.id.banner);
    banner.animateOpen();
    Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
         public void run() { 
              banner.animateClose();
         } 
    }, 2000); 

    //...

}

EDIT

Doing

final SlidingDrawer banner = (SlidingDrawer) findViewById(R.id.banner);
final Animation hideBanner = AnimationUtils.loadAnimation(this, R.anim.hide_banner);
banner.setAnimation(showBanner);

animates the handler only, even though I don't do banner.animateOpen() or banner.startAnimation(showbanner)!

like image 668
jul Avatar asked May 10 '11 17:05

jul


1 Answers

This youtube video shows a sliding drawer with a custom animation. You should be able to use or modify this code to solve your issue...

like image 176
starkej2 Avatar answered Nov 14 '22 01:11

starkej2