Android ->, wie zu animieren, um die neue position

Hier ist ein einfaches xml-android animation:

<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" />

Ich mich bewegen will, animierte Objekt aus der Mitte des Bildschirms, 0, 0 Positionen. Wie Katze ich es machen (es sollte funktionieren auf allen Bildschirm-Auflösungen)


Meine Antwort:

Danke Jungs für Eure Hilfe. Aber ich habe fix mein problem durch andere Weise, dynamisch ohne xml. Hier ist der vollständige code der Methode:

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);
    }

InformationsquelleAutor der Frage pleerock | 2011-09-02

Schreibe einen Kommentar