I have a DialogFragment which has some animations of some of the layouts inside its view. When I dismiss the dialog, I want to perform an animation and when the animation has ended, perform the dismiss operation.
Step1: Call the fragment from my activity:
myDialog.show(getSupportFragmentManager(), "");
Step 2: After the user had completed the job with the dialog, he presses a button. That button calls an animation and after that I want the dialog to disappear:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.my_layout, null);
layMain = (LinearLayout) layout.findViewById(R.id.layMain);
TextView btnCancel = (TextView) layout.findViewById(R.id.btnCancel);
btnCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
final Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.translate_to_bottom);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
dismiss();
}
});
layMain.startAnimation(anim);
}
});
.....
When the animations ends, the dialog gets dismissed but I get this error on logcat
E/ViewRootImpl(25507): Attempting to destroy the window while drawing! E/ViewRootImpl(25507): window=android.view.ViewRootImpl@427348e0, title=com.mypackage/com.mypackage.MyActivity
How can I prevent this ?
Later edit: if I am using it without any animation, everything works fine and no error is shown on logcat. So I suppose it has to do something with the animation.
The animation I am using:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="0%p"
android:interpolator="@android:anim/accelerate_interpolator"
android:toYDelta="80%p" />
</set>
post()
aRunnable
on it with thedismiss()
call. – CordillerasRunnable
with the dismiss() call on one of the dialog views(like btnCancel)? – Cordillerashandler.postDelayed()
? – FifinebtnCancel.post(new Runnable() { @Override public void run() {dismiss();}});
in theanimationEnd
callback. – Cordilleras