0

我有一个像这样设置的 WindowManager。

myWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.FILL_PARENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, 
        PixelFormat.TRANSLUCENT);
 myWindowManager.addView(view, params);

我像这样将 View 对象添加到 WindowManager 中。我想把这个 WindowManager 移到 TOP 中心。我不确定我该怎么做。有任何想法吗?

4

1 回答 1

0

您可以设置Gravity为您查看。IE

myWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.FILL_PARENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, 
        PixelFormat.TRANSLUCENT);
    //edited
    params.gravity=Gravity.TOP|Gravity.CENTER_HORIZONTA;

    myWindowManager.addView(view, params);

您也可以检查以获取更多详细信息。

于 2013-09-07T14:49:25.563 回答