是否可以使用“汉堡包”图标。来自Android的动画在另一个按钮? [英] Is it possible to use the "Hamburger icon" animation from Android in another button?

查看:337
本文介绍了是否可以使用“汉堡包”图标。来自Android的动画在另一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两个不同的位置放置两个汉堡图标,其中一个按钮位于通常位置(工具栏左侧),另一个按钮位于导航抽屉内。

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.

查看Android文档我看不到有关在其他位置使用hamburguer图标而不是工具栏的任何内容,所以我想知道是否有一种简单的方法来实现或复制动画到其他位置/按钮而不必自己做动画。

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.

提前谢谢

推荐答案

所以我在这个问题上有点晚了(只是遇到了同样的问题)。您可以使用底层可绘制的 DrawerArrowDrawable来自v7支持库的 。它根据它的进度 setProgress(floatValue)处理绘图,但是你需要处理状态之间的动画。我用 ValueAnimator 。请参见下面的示例:

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

这篇关于是否可以使用“汉堡包”图标。来自Android的动画在另一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆