ANDROID锁屏后解锁屏幕宽高反过来了

来源:互联网 发布:java中迭代器作用 编辑:程序博客网 时间:2024/04/29 23:43


程序设置为横屏:


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); }  















原创粉丝点击