How can a SlidingDrawer be animated?
Asked Answered
A

1

6

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)!

Adigun answered 10/5, 2011 at 17:26 Comment(2)
Try using setAnimation(...) to set an animation on your banner object before using animateOpen() / animateClose()Newport
I tried: only the handler is animated. The content is not visible :(Adigun
B
3

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...

Bouse answered 18/4, 2012 at 17:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.