gpt4 book ai didi

Android -> 如何动画到新位置

转载 作者:可可西里 更新时间:2023-11-01 18:45:40 24 4
gpt4 key购买 nike

这是简单的 xml android 动画:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:fromYDelta="0" android:toXDelta="-110"
android:toYDelta="-110" android:duration="1000" android:fillAfter="true" />

我想将动画对象从屏幕中心移动到 0, 0 位置。我是怎么做到的(它应该适用于所有屏幕分辨率)


我的回答:

谢谢大家的帮助。但是我已经通过其他方式动态地解决了我的问题,没有 xml。这是此方法的完整代码:

public void replace(int xTo, int yTo, float xScale, float yScale) {
// create set of animations
replaceAnimation = new AnimationSet(false);
// animations should be applied on the finish line
replaceAnimation.setFillAfter(true);

// create scale animation
ScaleAnimation scale = new ScaleAnimation(1.0f, xScale, 1.0f, yScale);
scale.setDuration(1000);

// create translation animation
TranslateAnimation trans = new TranslateAnimation(0, 0,
TranslateAnimation.ABSOLUTE, xTo - getLeft(), 0, 0,
TranslateAnimation.ABSOLUTE, yTo - getTop());
trans.setDuration(1000);

// add new animations to the set
replaceAnimation.addAnimation(scale);
replaceAnimation.addAnimation(trans);

// start our animation
startAnimation(replaceAnimation);
}

最佳答案

我的解决方案:

谢谢大家的帮助。但是我已经通过其他方式动态地解决了我的问题,没有 xml。这是此方法的完整代码:

public void replace(int xTo, int yTo, float xScale, float yScale) {
// create set of animations
replaceAnimation = new AnimationSet(false);
// animations should be applied on the finish line
replaceAnimation.setFillAfter(true);

// create scale animation
ScaleAnimation scale = new ScaleAnimation(1.0f, xScale, 1.0f, yScale);
scale.setDuration(1000);

// create translation animation
TranslateAnimation trans = new TranslateAnimation(0, 0,
TranslateAnimation.ABSOLUTE, xTo - getLeft(), 0, 0,
TranslateAnimation.ABSOLUTE, yTo - getTop());
trans.setDuration(1000);

// add new animations to the set
replaceAnimation.addAnimation(scale);
replaceAnimation.addAnimation(trans);

// start our animation
startAnimation(replaceAnimation);
}

关于Android -> 如何动画到新位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7283477/

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