Reputation: 516
I want to animate the view inside the popup window before dismissing it. So i have animated the view inside the dismiss listener like below,
penPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
TranslateAnimation animateSlideUp = new TranslateAnimation(0,0,0, mImageViewLike.getHeight());
animateSlideUp.setDuration(200);
animateSlideUp.setFillAfter(true);
mImageViewLike.startAnimation(animateSlideUp);
mImageViewLike.setVisibility(View.VISIBLE);
}
}, 200);
}
});
But this will not animate the imageview inside the popup window before closing the popup window and setOnDismissListener not called before closing the popup window. Could you please suggest me an idea to do any action before closing the popupwindow? Thanks in advance.
Upvotes: 2
Views: 3011
Reputation: 196
any action before closing the popupwindow?
You can extend PopupWindow and override dismiss method. Then you can call dismiss animation before super.
public class SomeClass extends PopupWindow {
@Override
public void dismiss() {
//TODO: animation here
super.dismiss();
}
}
Upvotes: 2
Reputation: 8149
If you start the animation on popup dismiss
then where you do the animation?.
You should do it in inverse way.
Start the animation
and when animation end
then dismiss
the dialog.
TranslateAnimation animateSlideUp = new TranslateAnimation(0,0,0, mImageViewLike.getHeight());
animateSlideUp.setDuration(200);
animateSlideUp.setFillAfter(true);
mImageViewLike.startAnimation(animateSlideUp);
animateSlideUp.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
penPopupWindow.dismiss();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
Upvotes: 2
Reputation: 7394
This is how you should do it,
1)Create Two Different set of animations.
say, popup_show.xml
and popup_hide.xml
and add it to your anim folder which you have to create inside res folder.
2)Now inside values folder create a xml called styles.xml
and add these animations to it like this,
<style name="Animation">
<item name="android:windowEnterAnimation">@anim/popup_show</item>
<item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>
3)Now set this style to your PopupWindow animation,
popup.setAnimationStyle(R.style.Animation);
Now it automatically detects Window Enter and Exit and provides with the required animation.
Upvotes: 3