int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
网上找了好多方式,基本就是两种个,但是我通过这个方式获取的值都为0,不知道为什么。有人遇到过这个问题吗?我想做底部的固定按钮区,但是没法获取View显示区域的高度。我是知道状态栏+标题栏是50px,但是不知道不同的手机上,会不会这个高度有区别,所以得要获取机器的值才行。有做过底部固定按钮的大侠,帮忙看看。

解决方案 »

  1.   

    同问。
    试过这个 http://android.group.javaeye.com/group/blog/836980
    取到的contentTop =0
      

  2.   

    public class MainActivity extends Activity {
    TextView textView;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            
        } @Override
    public void onWindowFocusChanged(boolean hasFocus) {
    // TODO Auto-generated method stub
    super.onWindowFocusChanged(hasFocus);
    Rect frame = new Rect();  
            getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);  
            int statusBarHeight = frame.top;
            int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();  
            //statusBarHeight是上面所求的状态栏的高度  
            int titleBarHeight = contentTop - statusBarHeight  ;
            
            textView = (TextView)findViewById(R.id.textView1);
            textView.setText("状态栏的高度" + Integer.toString(titleBarHeight));
    }
        
        
        
    }
      

  3.   

    状态栏+标题栏是50px这个一般是针对320*480分辨率的也即StatusBar高度+title的高度这个值是根据机器的分辨率来设置的,480*800的往往设置成38px