天天看點

Android 中文 API (90) —— WindowManager

正文

  一、結構

public interface WindowManager extends android.view.ViewManager

android.view.WindowManager

  二、概述 

  該接口用于與視窗管理器互動。通過 <code>Context.getSystemService(Context.WINDOW_SERVICE)</code>可以擷取到WindowManager的執行個體。(譯者注:如:WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);)

   參見

  三、内部類

  public static class WindowManager.LayoutParams

    (譯者注:繼承自android.view.ViewGroup.LayoutParams)

    public static class  WindowManager.BadTokenException       

    添加view時,如果該view的WindowManager.LayoutParams的令牌(token)無效,則會抛出該異常

  四、公共方法

  public abstract Display getDefaultDisplay()

           擷取預設的顯示對象

                   傳回值

                            預設的Display對象

  public abstract void removeViewImmediate (View view)

  參數

                   view 需要移除的視圖

  五、補充

  文章連結

示例代碼(來自文章連結的代碼)

public class WindowManagerDemo extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        TextView textView = (TextView) findViewById(R.id.label);

        WindowManager windowManager = (WindowManager) 

        getSystemService(Context.WINDOW_SERVICE);

        // print the current window's width and height on the title, eg: 320*480

    setTitle(windowManager.getDefaultDisplay().getWidth() + "*"

                + windowManager.getDefaultDisplay().getHeight());

        textView.setText("See the Title");

    }

}

本文轉自over140 51CTO部落格,原文連結:http://blog.51cto.com/over140/582416,如需轉載請自行聯系原作者

繼續閱讀