gpt4 book ai didi

android - 缩放 ObjectAnimator 后 View 宽度未更改

转载 作者:太空宇宙 更新时间:2023-11-03 11:13:36 25 4
gpt4 key购买 nike

在我为 scaleX 属性设置动画后,宽度不应该改变吗?我注意到当我减小 View 宽度时可点击区域会缩小,所以我想必须调整宽度。但是当我调用 view.getWidth() 时,我仍然得到初始值。

        Log.d(TAG, "" + getWidth()); //Initial value
setPivotX(getWidth() / 2);
ObjectAnimator animator = ObjectAnimator.ofFloat(this, View.SCALE_X, 1.0f, 0.8f);
animator.setInterpolator(new DecelerateInterpolator(1));
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {

}

@Override
public void onAnimationEnd(Animator animation) {
Log.d(TAG, "" + getWidth()); //Initial value :(
}

@Override
public void onAnimationCancel(Animator animation) {

}

@Override
public void onAnimationRepeat(Animator animation) {

}
});
animator.start();

最佳答案

我不认为 View 动画会改变这些属性(大小、边界或可见性)。您必须在动画结束时自己执行此操作。

来自:http://developer.android.com/guide/topics/graphics/view-animation.html

Note: Regardless of how your animation may move or resize, the bounds of the View that holds your animation will not automatically adjust to accommodate it. Even so, the animation will still be drawn beyond the bounds of its View and will not be clipped. However, clipping will occur if the animation exceeds the bounds of the parent View.

关于android - 缩放 ObjectAnimator 后 View 宽度未更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20858698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com