2012-07-10 15 views
5

Obecnie pracuję nad efektami przejścia dla mojego okna dialogowego. Proszę spojrzeć na obrazek poniżej: enter image description hereEfekty przejścia okna dialogowego

Animacja wejściowa dla mojego okna dialogowego powinna być od góry do środka. Podczas gdy animacja wyjścia powinna być od połowy do góry. Korzystam z następujących animacji XML, ale niestety, one nie działają.

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: To nie jest zwykły Dialog. Jest to activity nakładać Theme.Dialog w AndroidManifest.xml

+0

Jak się stosowania tych animacji? – Joru

+0

Myślę, że jeśli otworzysz "Dialogue Activity", to przejście to jest łatwe do wdrożenia. –

+0

czego używasz? DialogFragment? wklej kod, w którym chcesz zastosować przejścia i zatwierdzić transakcję. –

Odpowiedz

1

jeśli tworzysz okno jako działalność następnie można śledzić to podejście

Można utworzyć klasy animację:

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

oraz:

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

i wykorzystywać je z 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

Preferuję animacje XML niż zakodowane animacje .. –

+0

cóż, to jest twoje połączenie projektowe . Używam zakodowanych klas animacji, ponieważ można je ponownie wykorzystać w innym miejscu. –

+0

Animacje XML można również ponownie wykorzystać wszędzie. –

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" /> 
Powiązane problemy