popwindow通过setAnimationStyle(int animationStyle)函数来设置动画效果
android:windowEnterAnimation表示进入窗口动画
android:windowExitAnimation表示窗口退出动画
在res/values/style.xml代码:
在res/anim/popup_enter.xml声明所需进入动画
在res/anim/popup_exit.xml声明所需退出动画
设置popwindow的位置及动画
popupWindow.setAnimationStyle(R.style.PopupAnimation);
popupWindow.showAtLocation(findViewById(R.id.parent), Gravity.CENTER
| Gravity.CENTER, 0, 0);
popupWindow.update();
调用popupWindow.dismiss();语句。popwindow消失,自动调用消失动画popup_exit.xml
activity切换动画
public void onClick(View v) {
Intent intent = new Intent(ActivityAnim.this,ActivityTwo.class);
startActivity(intent);
overridePendingTransition(R.anim.act_enter,R.anim.act_exit);
}
overridePendingTransition(int ,int)函数,第一个参数为activity显示动画,第二个参数为退出动画,两个动画的xml文件存放在anim文件夹下
或者:getWindow().setWindowAnimations(R.style.window_animation);
去掉屏幕旋转的动画:
IWindowManager manager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
manager.setAnimationScale(1,0.0f);
在mainfest.xml中注册permission
<uses-permission android:name="android.permission.SET_ANIMATION_SCALE" />