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

查看:59
本文介绍了是否可以使用“汉堡包图标"?另一个按钮中来自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天全站免登陆