gpt4 book ai didi

android - 如何使用 ViewPropertyAnimator 将 Width 设置为特定值

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:03:49 33 4
gpt4 key购买 nike

如何使用 ViewPropertyAnimator 设置 View 宽度?

我可以缩放或平移(见下文)但我无法设置为特定宽度。

frame_1.animate().scaleX(5).scaleY(5).start();

但是没有

frame_1.animate().width(1024).height(768).start();

最佳答案

试试这个,甚至支持 Android 2.3:

    ValueAnimatorCompat exitAnimator = AnimatorCompatHelper.emptyValueAnimator();
exitAnimator.setDuration(TransitCompat.ANIM_DURATION * 4);
exitAnimator.addUpdateListener(new AnimatorUpdateListenerCompat() {
private float oldWidth = view.getWidth();
private float endWidth = 0;
private float oldHeight = view.getHeight();
private float endHeight = 0;
private Interpolator interpolator2 = new BakedBezierInterpolator();//Any other will be also O.K.

@Override
public void onAnimationUpdate(ValueAnimatorCompat animation) {
float fraction = interpolator2.getInterpolation(animation.getAnimatedFraction());

float width = oldWidth + (fraction * (endWidth - oldWidth));
mTarget.get().getLayoutParams().width = (int) width;

float height = oldHeight + (fraction * (endHeight - oldHeight));
view.getLayoutParams().height = (int) height;


view.requestLayout();
}
});

exitAnimator.start();

关于android - 如何使用 ViewPropertyAnimator 将 Width 设置为特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28600412/

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