240x320的高度為20px
320x480的高度為25px
480x800的高度為38px
不知道為什麼我寫的測試程式按照網上的說法老是擷取不到,以上是我google搜尋出來的結果。
以下是我寫的擷取標題列高度的代碼:
public void onCreate(Bundle savedInstanceState) {<br /> super.onCreate(savedInstanceState);</p><p> setContentView(R.layout.main);</p><p> mainLinear = (LinearLayout)findViewById(R.id.main);</p><p> setScreenSize();<br /> }</p><p> public void setScreenSize(){</p><p> Rect frame = new Rect();</p><p> getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);</p><p> int statusBarHeight = frame.bottom;</p><p> View view = getWindow().findViewById(Window.ID_ANDROID_CONTENT);</p><p> String sss = "top = " + view.getTop() + " bottom = " + view.getBottom(); </p><p>// int titleBarHeight = contentTop - statusBarHeight;<br />// System.out.println("titleBarHeight = " + titleBarHeight);</p><p> String ss = sss + "statusBarHeight = " + statusBarHeight;</p><p> Toast.makeText(this, ss, Toast.LENGTH_LONG).show();</p><p> WindowManager manager = this.getWindowManager();<br /> Display display = manager.getDefaultDisplay();</p><p> screenWidth = display.getWidth();<br /> screenHeight = display.getHeight();<br /> }