相关疑难解决方法(0)

Android - >如何动画到新位置

这是简单的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" />
Run Code Online (Sandbox Code Playgroud)

我想将动画对象从屏幕中心移动到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 …
Run Code Online (Sandbox Code Playgroud)

animation android android-2.2-froyo

15
推荐指数
2
解决办法
4万
查看次数

标签 统计

android ×1

android-2.2-froyo ×1

animation ×1