android - ActionBarSherlock 动画移动位置

标签 android android-animation actionbarsherlock

我的 ActionBarSherlock Actionbar 中有一个启动 AsyncTask 的菜单选项。我试图让图标在后台任务运行时进行动画处理。我让它工作,除了当我点击图标时,图标本身会向右“跳”几个像素,而且非常明显。不确定是什么导致了这种情况发生。

这是我目前所拥有的:

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);
    }
}

刷新 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"
/>

刷新.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,图标不会跳动,所以它与此有关。毫 headless 绪,快把我逼疯了。

最佳答案

我不知道这是否会产生任何影响,但如果您尝试使用 pivot 值,您可能会解决这个问题。也许只在一个轴上旋转?

关于android - ActionBarSherlock 动画移动位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10056083/

相关文章:

Android:自定义操作栏主题错误 -(未找到匹配的资源......)

Android Dagger Hilt : Do we need scope annotations for ViewModels?

java - Android - 连接到蓝牙模块

Android 使用 CustomLayout 设置 ActionBar 字体

android - 动 Canvas 局以填充屏幕

Android Flip Animation 从周围增长淡入,向周围收缩淡出?

android - 加载 fragment 没有淡入或淡出

android - 如何制作带有图标下方文本的操作栏选项卡菜单?

android - 在自定义 View 中显示 Action 的 Toast

android - 类似 evernote 的操作栏 - 向上按钮和选项卡在顶部的一行中,菜单操作在底部