Moving and resizing DrawerLayout’s content on sliding

person shubham sharmafolder_openAndroid, Animationlocal_offer, access_time June 6, 2018

You can do this by translating and scaling the content View in the onDrawerSlide() method of a DrawerListener on your DrawerLayout. Since the content View itself is resizing, and there’s a separate TextView that appears in the bottom right corner, we’ll stick both of these in another holder ViewGroup. If that label TextView isn’t needed, the holder ViewGroup can be omitted, as well.

A basic DrawerLayout setup for the example:

 

The example Activity shows the standard View initializations, and the DrawerListener that is actually doing the work.

 

The example uses a SimpleDrawerListener, but the onDrawerSlide() method can be overridden similarly in an ActionBarDrawerToggle, if using that. The super method would need to be called, in that case, to preserve the hamburger-arrow animation.

Do note that DrawerLayout retains the drawer state during Activity recreation, so you might need to account for this when handing orientation changes, etc.

warningComments are closed.