2013-02-25 24 views
11

Wie kann ich Animation zu DialogFragment hinzufügen? Meine Animationen sind:Wie füge ich Animation zu DialogFragment hinzu?

aus anim:

<scale 
    android:duration="200" 
    android:fillAfter="false" 
    android:fromXScale="1.0" 
    android:fromYScale="1.0" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:pivotX="50%" 
    android:pivotY="-90%" 
    android:startOffset="200" 
    android:toXScale="0.5" 
    android:toYScale="0.5" /> 

<translate 
    android:duration="300" 
    android:fromXDelta="0" 
    android:fromYDelta="0" 
    android:toXDelta="-200" 
    android:toYDelta="-200" /> 

in anim:

<scale 
    android:duration="200" 
    android:fillAfter="false" 
    android:fromXScale="0.5" 
    android:fromYScale="0.5" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:pivotX="50%" 
    android:pivotY="-90%" 
    android:toXScale="1.0" 
    android:toYScale="1.0" /> 

<translate 
    android:duration="300" 
    android:fromXDelta="-200" 
    android:fromYDelta="-200" 
    android:toXDelta="0" 
    android:toYDelta="0" /> 

und mein Code:

FragmentTransaction ft = getFragmentManager().beginTransaction(); 
       ft.setCustomAnimations(R.anim.jump_in, R.anim.jump_out, R.anim.jump_in, R.anim.jump_out); 
       ft.add(layer_frag, "layer frag"); 
       ft.show(layer_frag).commit();//layer_frag is a class whitch extends DialogFragment 

ich etwas verpassen muss, weil es, wie es vorher angezeigt erscheint.

+0

Ihre Antwort ist hier: http://stackoverflow.com/a/13537234/969325. Kurz gesagt, du musst dich damit herumschlagen, da es keine Einbauten gibt. – Warpzit

+0

Wahrscheinlich nicht, weil ich das gemacht habe und es funktioniert auch nicht für mich :(es hat das Layout ein bisschen geändert, aber die Animation funktioniert nicht – Csabi

+0

Dann denke ich, dass Sie mit der Erstellung Ihres eigenen Fragments, das als Dialog erscheint. – Warpzit

Antwort

15
@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) 
{ 
    final Dialog dialog = super.onCreateDialog(savedInstanceState); 
    dialog.getWindow().getAttributes().windowAnimations = R.style.detailDialogAnimation; 
    return dialog; 
} 

Die Antwort war von stackoverflow.com/a/13537234/969325 aber Sie haben den Stil bei onCreateDialog Funktion zu setzen.

+0

Wissen Sie, ob es eine Möglichkeit gibt, einen Rückruf zu erhalten, wenn diese Animationen fertig sind? Ich möchte eine 2-teilige Animation machen, eine, in der das Dialogfeld eingeblendet wird, und dann die Ansichten ausblenden Wie würde ich anhängen ein Zuhörer zum FensterAnimationen? –

+0

setAnimationListener (neu AnimationListener() { \t \t \t \t \t \t \t \t \t \t \t \t public void onAnimationStart (Animation Animation) { \t \t \t \t \t // TODO Automatisch generierte Methode Stub \t \t \t \t \t \t \t \t \t} \t \t \t \t \t \t \t \t \t \t \t \t public void onAnimationRepeat (Animation Animation) { \t \t \t \t \t // TODO Automatisch generierte Methode Stub \t \t \t \t \t \t \t \t \t} \t \t \t \t \t \t \t \t \t \t \t public void onAnimationEnd (Animation Animation) { \t \t \t \t \t ladder.startAnimation (toRight); \t \t \t \t \t \t \t \t \t} \t \t \t}); – Csabi

+0

Sie müssen den Stil nicht in 'onCreateDialog' einstellen, da Sie den Dialog jederzeit mit' getDialog' aufrufen können, nachdem 'onCreateDialog' aufgerufen wurde. Ich rufe es zum Beispiel in 'onViewCreated' auf. – sotrh

Verwandte Themen