程序设置为横屏:
android:screenOrientation="landscape"
希望获得屏幕宽高
@Override
public void onWindowFocusChanged(boolean hasFocus) {
height = rl.getHeight();
width = rl.getWidth();
logCat("rl.getHeight() " + height + "rl.getWidth() " + width );
super.onWindowFocusChanged(hasFocus);
}
上面代码在大部分手机正常
但是少部分手机,锁屏后再解锁,就会发现宽高反过来了。
所以要改成这样
static boolean m_bIs1stFocus=true;
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if( m_bIs1stFocus ){
m_bIs1stFocus=false;
height = rl.getHeight();
width = rl.getWidth();
logCat("rl.getHeight() " + height + "rl.getWidth() " + width + " hasFocus:" + hasFocus);
}
super.onWindowFocusChanged(hasFocus);
}