2012-07-10 11 views
5

Ich arbeite gerade an den Übergangseffekten für meinen Dialog. Bitte beachten Sie das Bild unten: enter image description hereDialog Übergangseffekte

Die Eingangsanimation für meinen Dialog sollte von oben nach Mitte sein. Während die Ausgangsanimation von Mitte bis Anfang sein sollte. Ich verwende die folgenden XML-Animationen, aber leider funktionieren sie nicht.

slide_down.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
<translate android:fromYDelta="100%p" android:toYDelta="0" 
android:duration="1000"/> 
</set> 

slide_up.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
android:fromYDelta="0%p" android:toYDelta="50%p" 
android:duration="1000"/> 

EDIT: Dies ist kein gewöhnlicher Dialog. Es ist ein activity mit einem Theme.Dialog im

+0

Wie bewerben Sie sich diese Animationen? – Joru

+0

Ich denke, wenn Sie "Dialogue Activity" öffnen, dann ist dieser Übergang einfach zu implementieren. –

+0

Was benutzen Sie? DialogFragment? fügen Sie den Code ein, in dem Sie die Übergänge anwenden, und übertragen Sie die Transaktion bitte. –

Antwort

1

AndroidManifest.xml angewendet, wenn Sie den Dialog als eine Aktivität erstellen, dann können Sie diesen Ansatz folgen

Sie können die Animation-Klassen erstellen:

public class DropDownToMiddleAnimation extends Animation { 
    public int height, width; 

    @Override 
    public void initialize(int width, int height, int parentWidth, 
      int parentHeight) { 
     // TODO Auto-generated method stub 
     super.initialize(width, height, parentWidth, parentHeight); 
     this.width = width; 
     this.height = height; 
     setDuration(500); 
     setFillAfter(true); 
     setInterpolator(new LinearInterpolator()); 
    } 

    Camera camera = new Camera(); 

    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 
     // TODO Auto-generated method stub 
     super.applyTransformation(interpolatedTime, t); 

     Matrix matrix = t.getMatrix(); 
     camera.save(); 

     camera.getMatrix(matrix); 
     matrix.setTranslate(0, ((height/2) * interpolatedTime))); 

     matrix.preTranslate(0, -height); 
     camera.restore(); 

     this.setAnimationListener(this); 
    } 

und:

public class MiddleToTopAnimation extends Animation { 
    public int height, width; 

    @Override 
    public void initialize(int width, int height, int parentWidth, 
      int parentHeight) { 
     // TODO Auto-generated method stub 
     super.initialize(width, height, parentWidth, parentHeight); 
     this.width = width; 
     this.height = height; 
     setDuration(500); 
     setFillAfter(true); 
     setInterpolator(new LinearInterpolator()); 
    } 

    Camera camera = new Camera(); 

    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 
     // TODO Auto-generated method stub 
     super.applyTransformation(interpolatedTime, t); 

     Matrix matrix = t.getMatrix(); 
     camera.save(); 

     camera.getMatrix(matrix); 
     matrix.setTranslate(0, -((height/2) * interpolatedTime)));//here is the change 

     matrix.preTranslate(0, -height); 
     camera.restore(); 

     this.setAnimationListener(this); 
    } 

und verwenden sie sie mit Ihrem Dialog

LinearLayout ll = (LinearLayout) findViewById(R.id.parentLayout);//parent layout in the xml, which serves as the background in the custom dialog 

ll.startAnimation(new DropDownToMiddleAnimation());//use with launching of the dialog 

ll.startAnimation(new MiddleToTopAnimation());//use while dismissing the dialog/finishing the dialog activity 
+1

Ich bevorzuge XML-Animationen als fest codierte Animationen .. –

+0

Nun, das ist dein Design-Aufruf . Ich verwende hartcodierte Animationsklassen, da sie anderswo wiederverwendet werden können. –

+0

XML-Animationen können auch überall wiederverwendet werden. –

2

slide_down.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="@android:integer/config_longAnimTime" 
    android:fromYDelta="-50%p" 
    android:toYDelta="0%p" /> 

slide_up.xml

<?xml version="1.0" encoding="utf-8"?> 
<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="@android:integer/config_longAnimTime" 
    android:fromYDelta="0%p" 
    android:toYDelta="-100%p" /> 
Verwandte Themen