我已在res/anim/
中定義了一個PopupWindow
和一個定義的XML縮放動畫,該動畫適用於顯示和關閉該彈出窗口。但情況是我想動態改變pivotX
和pivotY
動畫的樣式,所以它從屏幕的不同點開始(增長)。在Android中以編程方式更改彈出式窗口動畫
因此,我可以在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。我可以使用Dialog
或任何我可以實現這樣的行爲。你能幫忙嗎?