Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
弹出窗口动画在Android中以编程方式更改_Android_Animation - Fatal编程技术网

弹出窗口动画在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);
    
    而不是

    popupView.setAnimation(scaleAnimation);
    
    或者在调用“setAnimation”之前设置动画的开始时间,并确保在动画开始时视图的父视图无效

  • 替换

    this.popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    

    其中,在缩放过程中和之后,宽度和高度必须大于“popupView”的尺寸。使用LayoutParams.WRAP_内容时,ScaleAnimation将不起作用

希望能有帮助

this.popupWindow = new PopupWindow(popupView, width, height);