动画抽屉图标变成箭头setDisplayHomeAsUpEnabled? [英] Animate drawer icon into arrow on setDisplayHomeAsUpEnabled?

查看:1872
本文介绍了动画抽屉图标变成箭头setDisplayHomeAsUpEnabled?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用setDisplayHomeAsUpEnabled为了显示箭头,而不是抽屉汉堡包的图标,但它没有得到动画或任何东西。相反,它显示了箭头绘制瞬间。

I'm using setDisplayHomeAsUpEnabled in order to show the arrow instead of the drawer "burger" icon but it's not getting animated or anything. Instead it shows the arrow drawable instantaneously.

主屏幕:(相册1)

当你点击一个电影:(相册2)

关键是,该图标也动画就好了,当我将抽屉,这让我觉得,也许我不应该使用setDisplayHomeAsUpEnabled此:(相册3)

The thing is, the icon does the animation just fine when I slide the drawer, which makes me think that maybe I'm not supposed to use setDisplayHomeAsUpEnabled for this: (Album 3)

专辑: http://imgur.com/a/LkXbh

下面是我的抽屉里拨动code:

Here's my drawer toggle code:

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);

    drawerAdapter = new DrawerAdapter(this, App.getNavItems(), getSupportFragmentManager());
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerList = (ExpandableListView) findViewById(R.id.left_drawer);

    // Set onGroupClick and onChildClick
    drawerAdapter.setClickEvents(MainActivity.this, drawerLayout, drawerList);
    drawerList.setAdapter(drawerAdapter);

    ActionBarDrawerToggle toolbarDrawerToggle = new ActionBarDrawerToggle(
            this,                 
            drawerLayout,        
            toolbar,             
            R.string.drawer_open, 
            R.string.drawer_close 
    ) {

        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View view) {
            super.onDrawerOpened(view);
            invalidateOptionsMenu();
        }
    };
    drawerLayout.setDrawerListener(toolbarDrawerToggle);
    toolbarDrawerToggle.syncState();

编辑:我希望动画没有打开抽屉时,该工作了。 我想手动触发动画,当我打开一个特定的片段。我可能没有正确地解释自己。

I want the animation not when opening the drawer, that works already. I would like to manually trigger the animation when I load a specific fragment. I may not have explained myself correctly.

推荐答案

我没有测试过这一点,但你可以通过在0动画花车来实现这一(抽屉关闭)和1(抽屉打开),然后值传递到 ActionBarDrawerToggle.onDrawerSlide(查看和float)。我相信这是如何切换决定了国家的动画切换应该是

I haven't tested this, but you may be able to achieve this by animating a float between 0 (drawer closed) and 1 (drawer open) and then passing the value into ActionBarDrawerToggle.onDrawerSlide(View, float). I believe that's how the toggle determines what state the animated toggle should be in.

这样的事情应该工作。

ValueAnimator anim = ValueAnimator.ofFloat(start, end);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator valueAnimator) {
        float slideOffset = (Float) valueAnimator.getAnimatedValue();
        toolbarDrawerToggle.onDrawerSlide(drawerLayout, slideOffset);
    }
});
anim.setInterpolator(new DecelerateInterpolator());
// You can change this duration to more closely match that of the default animation.
anim.setDuration(500);
anim.start();

这篇关于动画抽屉图标变成箭头setDisplayHomeAsUpEnabled?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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