Show Dialogfragment with Animation Growing from a Point

How to add animation to DialogFragment?

@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.

Animation With DialogFragment Android

The reason was that animations on device were disabled.

Shrink/Grow layout w/ animation on DialogFragment

You can define a custom animator that updates the height property at each frame of the animation. For example:

int startHeight = slideDownView.getHeight();
// Note that you should not hardcode "300" as that will be different pixel values on
// different devices - get the value from a dimen resource or scale by the
// device density
int endHeight = startHeight - getDistanceToAnimate();

// Create a simple int animator that animates between the starting and ending height
ValueAnimator animator = ValueAnimator.ofInt(startHeight, endHeight);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
// On each frame, update the view height
int value = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.height = value;
view.setLayoutParams(layoutParams);
}

@Override
public void onAnimationEnd(Animator animation) {
// Once the animation finishes, you might have to update the view's final
// height and / or its `layout_height` attribute.
}
});

animator.setDuration(getAnimationTime());
animator.start();

Hope that helps!

Navigation Architecture Component: transition animations not working for dialog

As of version 2.2.0-alpha02 this is the limitation of Navigation component. You can view the source code of DialogFragmentNavigator

However, you can pretty easily achieve animation for DialogFragment using the following steps:

  1. Create a style mentioning the enter and exit animations from anim folder:
    <style name="MyDialogAnimation">
<item name="android:windowEnterAnimation">@anim/enter_anim</item>
<item name="android:windowExitAnimation">@anim/exit_anim</item>
</style>

  1. Inside the DialogFragment set the style as windowAnimations
     override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
dialog?.window?.attributes?.windowAnimations = R.style.MyDialogAnimation
}

Find more here.

FragmentDialog animate an layout on dismiss

As found here https://stackoverflow.com/a/8209841/379865 the solution that works is pretty simple: get the dialog and listen for key presses.

getDialog().setOnKeyListener(new OnKeyListener() {

@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK)
{
final Animation anim =
AnimationUtils.loadAnimation(getActivity(),
R.anim.translate_to_bottom);
anim.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationEnd(Animation animation) {
dismiss();

}
});
layMain.startAnimation(anim);
return true;
}
return false;
}
});


Related Topics



Leave a reply



Submit