ActionBarSherlock动画移动位置 [英] ActionBarSherlock animation moves position

查看:99
本文介绍了ActionBarSherlock动画移动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个揭开序幕的AsyncTask的在我的ActionBarSherlock动作条的菜单选项。我试图让后台任务运行时的动画图标。我有工作,除了当我点击图标,图标本身就会跳了几个像素到正确的,这是非常明显的。不完全知道是什么原因造成这种情况发生。

I have a menu option in my ActionBarSherlock Actionbar that kicks off an AsyncTask. I'm trying to get the icon to animate while the background task is running. I have it working, except when I click on the icon, the icon itself will "jump" a couple pixels over to the right, and it's very noticeable. Not exactly sure what is causing that to happen.

这是我到目前为止有:

private MenuItem refreshItem;   

private void DoRefresh() 
{
    final LayoutInflater inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final ImageView ivRefresh = (ImageView)inflater.inflate(R.layout.refresh_view, null);

    final Animation rotation = AnimationUtils.loadAnimation(activity, R.anim.refresh);
    ImageView ivRefresh.startAnimation(rotation);

    refreshItem.setActionView(ivRefresh);

    //AsyncTask is kicked off here
}

@Override
public boolean onOptionsItemSelected(final MenuItem item) 
{
    if (item.getItemId() == R.id.refresh) {
        refreshItem = item;
        this.DoRefresh();
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}

refresh_view.xml

refresh_view.xml

<?xml version="1.0" encoding="utf-8"?>

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/refresh"
/>

refresh.xml     

refresh.xml

<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="1100" 
/>

更新:

一直打打闹闹这一点,没有运气。它无关,与动画,因为如果我禁用了动画,图标还是跃过的权利。如果我注释掉 setActionView ,图标不跳,所以它是与这一点。不知道,我发疯。

Been fooling around with this, with no luck. It has nothing to do with the animation because if I disable the animation, the icon still jumps over to the right. If I comment out setActionView, the icon does not jump, so it has something to do with that. Have no clue, driving me nuts.

推荐答案

如果菜单选项是一个操作项,你应该风格Widget.Sherlock.ActionButton应用到的ImageView,以保持一致性。阅读这篇文章,我写了关于如何正确制作动画的行动项目。 http://alexfu.tumblr.com/post/19414506327/android -dev-动画动作项

If the menu option is an action item, you should apply the style Widget.Sherlock.ActionButton to the ImageView to keep consistency. Read this article I wrote on how to animate action items properly. http://alexfu.tumblr.com/post/19414506327/android-dev-animate-action-items

这篇关于ActionBarSherlock动画移动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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