我使用 ObjectAnimator 在我的应用程序中移动一些视图,一切正常,但我无法使用 gettop、getleft 函数获取视图位置,它们总是返回 0。我的项目 min sdk 为 14。我也尝试使用 getViewTreeObserver 但仍然得到相同的结果。
but = (Button) findViewById(R.id.but1);
ObjectAnimator _animationStrategy = ObjectAnimator.ofFloat(but, View.TRANSLATION_X, 500);
_animationStrategy.setDuration(5000);
_animationStrategy.setInterpolator(new AccelerateDecelerateInterpolator());
_animationStrategy.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Log.d("test","posX="+but.getLeft()+" posY="+but.getTop());
}
});
_animationStrategy.start();