弹出窗口动画在Android中以编程方式更改
我已经在弹出窗口动画在Android中以编程方式更改,android,animation,Android,Animation,我已经在res/anim/中有了一个PopupWindow和一个定义的XML比例动画,它在显示和关闭该弹出窗口时应用。但情况是,我想动态更改动画样式的pivotX和pivotyy,使其从屏幕的不同点开始(增长) 因此,我可以在res/anim/in.xml中动态更改pivotX和pivotY,或者创建新的ScaleAnimation并应用它。我不知道如何做第一个选项,不幸的是,当我写以下内容时,后一个选项不起作用: public class MyPopup { private Popu
res/anim/
中有了一个PopupWindow
和一个定义的XML比例动画,它在显示和关闭该弹出窗口时应用。但情况是,我想动态更改动画样式的pivotX
和pivotyy
,使其从屏幕的不同点开始(增长)
因此,我可以在res/anim/in.xml
中动态更改pivotX
和pivotY
,或者创建新的ScaleAnimation
并应用它。我不知道如何做第一个选项,不幸的是,当我写以下内容时,后一个选项不起作用:
public class MyPopup {
private PopupWindow popupWindow;
private Integer growFromX;
private Integer growFromY;
public MyPopup(Integer growFromX, Integer growFromY) {
if (growFromX != null && growFromY != null) {
this.growFromX = growFromX.intValue();
this.growFromY = growFromY.intValue();
}
}
public void show() {
LayoutInflater layoutInflater = (LayoutInflater) this.activity
.getBaseContext().getSystemService(
Activity.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(
R.layout.map_selector_dialog_layout, null);
ScaleAnimation scaleAnimation = new ScaleAnimation(0.0f, 0.0f,
1.0f, 1.0f, Animation.RELATIVE_TO_SELF,
(float) this.growFromX, Animation.RELATIVE_TO_SELF,
(float) this.growFromY);
scaleAnimation.setFillAfter(false);
scaleAnimation.setDuration(4000);
popupView.setAnimation(scaleAnimation);
this.popupWindow = new PopupWindow(popupView,
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
this.popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
}
}
它不必是WindowPopup。我可以使用
对话框
或其他任何方法来实现这种行为。你能帮忙吗 要使代码正常工作,需要调整的地方很少:
- 设置“popupWindow”中“popupView”的宽度和高度
- 为缩放动画设置插值器
- 任用
而不是popupView.startAnimation(scaleAnimation);
或者在调用“setAnimation”之前设置动画的开始时间,并确保在动画开始时视图的父视图无效popupView.setAnimation(scaleAnimation);
- 替换
与 其中,在缩放过程中和之后,宽度和高度必须大于“popupView”的尺寸。使用LayoutParams.WRAP_内容时,ScaleAnimation将不起作用this.popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
this.popupWindow = new PopupWindow(popupView, width, height);