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>
The only solution that works so far, without throwing an error is this:
@Override
public void onAnimationEnd(Animation animation) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
dismiss();
}
}, 10);
}
I am open to any other sugestions
You have pass fragment context as a getSupportFragmentManager(). So you have to change it:
myDialog.show(getFragmentManager(), "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With