onCreateShowAnimation

返回一个Animation,在BasePopup显示的时候执行,返回为null则不执行动画。

示例

  1. public class DemoPopup extends BasePopupWindow {
  2. public DemoPopup(Context context) {
  3. super(context);
  4. setContentView(R.layout.popup_normal);
  5. }
  6. @Override
  7. protected Animation onCreateShowAnimation() {
  8. Animation showAnimation = new ScaleAnimation(0, 1f, 0, 1f);
  9. showAnimation.setDuration(500);
  10. return showAnimation;
  11. }
  12. }

wiki_onCreateShowAnimation.gif

onCreateShowAnimator

返回一个Animator,在BasePopup显示的时候执行,返回为null则不执行动画。

示例

  1. public class DemoPopup extends BasePopupWindow {
  2. public DemoPopup(Context context) {
  3. super(context);
  4. setContentView(R.layout.popup_normal);
  5. //不裁剪contentView
  6. setClipChildren(false);
  7. }
  8. @Override
  9. protected Animator onCreateShowAnimator() {
  10. ObjectAnimator showAnimator = ObjectAnimator.ofFloat(getDisplayAnimateView(), View.TRANSLATION_Y, getHeight() * 0.75f, 0);
  11. showAnimator.setDuration(1000);
  12. showAnimator.setInterpolator(new OvershootInterpolator(6));
  13. return showAnimator;
  14. }
  15. }

wiki_onCreateShowAnimator.gif

提示
Animation的优先级比Animator优先级高,两者都传则取Animation
如果在创建动画时需要宽高信息,请覆写onCreateShowAnimator(int width, int height)方法(该方法在2.2.2版本中添加)
如果您不想写那么繁琐的动画,建议升级到2.2.4或更高的版本并使用AnimationHelper,详见文档