Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add animation to DialogFragment?

How can I add animation to DialogFragment. My animations are:

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

and my 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

I must miss something because it appears as it appears before.

like image 692
Csabi Avatar asked Feb 25 '13 09:02

Csabi


People also ask

Is DialogFragment deprecated?

This method is deprecated. androidx.

What is the difference between dialog & DialogFragment?

Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.

How do you show DialogFragment?

Showing the DialogFragment It is not necessary to manually create a FragmentTransaction to display your DialogFragment . Instead, use the show() method to display your dialog. You can pass a reference to a FragmentManager and a String to use as a FragmentTransaction tag.


1 Answers

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

The answer was from stackoverflow.com/a/13537234/969325 but You have to set the style at onCreateDialog function.

like image 106
Csabi Avatar answered Oct 12 '22 23:10

Csabi