2011-02-25 48 views

回答

4

同時,我找到了解決辦法。在honycomb中有一個新的OnLayoutChangeListener事件,它允許您等待佈局完成,然後測量佈局的大小而不是屏幕大小。

6

順便說一句......爲別人喜歡我,誰在這個問題尋找實際數量迷迷糊糊的,它的48個像素(在摩托羅拉XOOM,至少)。這是基於該測試活動的調試輸出結果,該測試活動結合了一個沒有標題欄的主題(例如,@android:style/Theme.NoTitleBar)和一個高度和寬度都設置爲「高度」的單視圖LinearLayout。 match_parent」(例如,創建新的機器人應用程序時創建的):

package com.sample.layouttest; 

import android.app.Activity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnLayoutChangeListener; 

public class Main extends Activity implements OnLayoutChangeListener { 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     View newView = getLayoutInflater().inflate(R.layout.main, null); 
    newView.addOnLayoutChangeListener(this); 
    setContentView(newView); 
    } 

    @Override 
    public void onLayoutChange(View view, int left, int top, int right, 
      int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { 
     Log.d("LayoutTest","left="+left+", top="+top+", right="+right+", bottom="+bottom); 
    } 
} 

在一個摩托羅拉的Xoom運行Android 3.1(以及一個三星Galaxy 10.1V運行3.0),從onLayoutChange方法中,當輸出進入人像模式是:

05-24 15:11:43.047: DEBUG/LayoutTest(8658): left=0, top=0, right=800, bottom=1232 

,並在進入時的景觀:

05-24 15:13:18.837: DEBUG/LayoutTest(8658): left=0, top=0, right=1280, bottom=752