WindowManager 为每个视图维护至少两个LayoutParams
类的实例,除了它View
本身。
的检查updateViewLayout
方法WindowManager
,特别是这部分:
view.setLayoutParams(wparams);
synchronized (this) {
int index = findViewLocked(view, true);
ViewRoot root = mRoots[index];
mParams[index] = wparams;
root.setLayoutParams(wparams, false);
}
我相信你可以通过layout
直接调用来制造一些混乱。改为使用WindowManager.updateViewLayout
。它会更慢,但安全(只是 IMO)。
更新
[来自:https ://stackoverflow.com/a/11188273/327011 ]
WindowManager windowsManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)
WindowManager.LayoutParams windowParams = new WindowManager.LayoutParams();
windowParams.x = <new X coord>;
windowParams.y = <new Y coord>
windowParams.height = myImageView.getHeight();
windowParams.width = myImageView.getWidth();
windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
windowParams.format = PixelFormat.TRANSLUCENT;
windowParams.windowAnimations = 0;
windowManager.updateViewLayout(myImageView, windowParams);