setPivotX 在 android 4.1.1 NineOldAndroid 上不起作用



我正在使用scaleX()ImageView设置动画。这应该是一个从左到右填充的进度条。它在API 10、18和19上工作时没有问题。但在API 16上,setPivotX()方法似乎存在问题。我已经尝试了NineOldAndroids中的每个选项:设置视图枢轴。

final ImageView progressBarFill = (ImageView) getView().findViewById(R.id.progressbarImageFill);
//...
ViewHelper.setPivotX(progressBarFill, 0);
AnimatorProxy.wrap(progressBarFill).setPivotX(0);
animate(progressBarFill).setDuration(1000).scaleX(0.25f);

AnimatorSet set = new AnimatorSet();
set.playTogether(
    ObjectAnimator.ofFloat(progressBarFill, "scaleX", 0f, 0.25f)
);
AnimatorProxy.wrap(progressBarFill).setPivotX(0.0f);
ViewHelper.setPivotX(progressBarFill, 0f);
set.setDuration(1000).start();

动画工作,但它从ImageView的中心设置动画。有人能证实这个问题吗?

更新

我也尝试过使用机器人的标准动画包:

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    progressBarFill.setVisibility(View.VISIBLE);
    progressBarFill.setPivotX(0);
    progressBarFill.setPivotY(0);
    AnimatorSet set = new AnimatorSet();
    set.playTogether(
        ObjectAnimator.ofFloat(progressBarFill, "scaleX", 0f, 0.25f)
    );
    set.setDuration(2000).start();
}

但它仍然不能在安卓API 16上运行。因此,这个问题不仅与NineOldAndroids库有关,还与标准动画功能有关。

事实证明,在API 16中,将枢轴X设置为0并不适用。因此,将轴心设置在视图progressBarFill.setPivotX(1);的最左边效果要好得多。

最新更新