更新Android中WindowManager内部视图的问题

时间:2015-04-28 14:19:28

标签: android layout view android-windowmanager

以下是添加WindowManager以保持在其他视图之上的代码。

DT

工作正常。在窗口管理器内部布局并动态更新布局。但我无法更新视图。

private View mainView;
private WindowManager.LayoutParams params;
windowManager = (WindowManager) getSystemService(Service.WINDOW_SERVICE);
       params = new WindowManager.LayoutParams(
               WindowManager.LayoutParams.WRAP_CONTENT,
               WindowManager.LayoutParams.WRAP_CONTENT,
               WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
               WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_FULLSCREEN,
               PixelFormat.TRANSLUCENT);

params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = 0;
params.y = 0;
windowManager.addView(mainView, params);

调用setText方法,没有异常,但视图未更新。任何人都可以在这里指出这个问题吗?

1 个答案:

答案 0 :(得分:0)

更新您要修改的特定视图:

// Get teh view params
WindowManager.LayoutParams paramNameTV = (WindowManager.LayoutParams) callerNameTv .getLayoutParams(); 
//update the view layout
windowManager.updateViewLayout(callerNameTv, paramNameTV );