通过WindowManager添加view以及添加动画

//
mWm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.format = PixelFormat.TRANSLUCENT;
        params.type = WindowManager.LayoutParams.TYPE_TOAST;

 params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | 
// 表示window不需要获取焦点,也不需要接收各种输入事件            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
params.gravity = Gravity.TOP;
//添加动画
params.windowAnimations = R.style.notice_dialog_anim_bottom2top;

下面是加载动画的一个资源文件

notice_dialog_anim_top2bottom_in

<translate xmlns:android="http://schemas.android.com/apk/res/android"
           android:duration="1000"
           android:fromXDelta="0"
           android:fromYDelta="-100%"
           android:toXDelta="0"
           android:toYDelta="0">

translate>

notice_dialog_anim_top2bottom_out

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromYDelta="0"
    android:fromXDelta="0"
    android:toXDelta="0"
    android:toYDelta="-100%" >

translate>

你可能感兴趣的:(通过WindowManager添加view以及添加动画)