gpt4 book ai didi

android - 如何在 Android 中为 LayoutParams x 和 y 设置动画

转载 作者:行者123 更新时间:2023-11-29 17:39:29 26 4
gpt4 key购买 nike

我是安卓新手。我有以下代码:

// layoutParams of type WindowManager.LayoutParams
layoutParams.x = someX;
layoutParams.y = someY;
windowManager.updateViewLayout(someView, layoutParams);

我如何激活这种变化?翻译之类的东西...

最佳答案

您可以使用ValueAnimator:

int beginValue = 0;
int endValue = 100;

ValueAnimator animator = ValueAnimator.ofInt(beginValue, endValue);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
WindowManager.LayoutParams layoutParams =
(WindowManager.LayoutParams) view.getLayoutParams();
layoutParams.x = (Integer) animation.getAnimatedValue();
layoutParams.y = (Integer) animation.getAnimatedValue();
getWindowManager().updateViewLayout(view, params);
}
});
animator.start();

关于android - 如何在 Android 中为 LayoutParams x 和 y 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29213035/

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