Is it possible to use the “Hamburger icon” animation from Android in another button?

女生的网名这么多〃 提交于 2019-12-11 03:33:40

问题


I would like to have two Hamburger icon with its animation in two different positions, one button in the usually place (at the left in my toolbar) and other in a button placed inside the Navigation Drawer.

Looking the Android documentation I couldn't see anything talking about using the hamburguer icon in other position more than the toolbar, so I would like to know if there is an easy way to implement or copy the animation to other position/button without having to do my own animation.

Thank you in advance


回答1:


So I am a little late on this one (only just came across the same problem). You can use the underlying drawable DrawerArrowDrawable from the v7 support library. It handles the drawing based on it's progress setProgress(floatValue) but you need to handle the animation between states. I did this by wrapping it with a ValueAnimator. See example below:

final DrawerArrowDrawable drawable = new DrawerArrowDrawable(this);
ImageView imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageDrawable(drawable);

ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  @Override public void onAnimationUpdate(ValueAnimator animation) {
    drawable.setProgress((Float)animation.getAnimatedValue());
  }
});

...

// burger to arrow
animator.start();

...

// arrow to burger
animator.reverse();

This is an untested adaption from a production app, should work though :-)




回答2:


There are several implementations of the hamburger menu icon animation. You could try to use one of those. Take a look at this project:

https://github.com/keklikhasan/LDrawer

You could use the animation without the drawer. I hope this helps you.



来源:https://stackoverflow.com/questions/33124555/is-it-possible-to-use-the-hamburger-icon-animation-from-android-in-another-but

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!