2011-08-11 61 views
0

我有一個應用程序的計時器,我的應用程序應始終處於LandScape模式。我正在代碼中獲取我的主佈局的寬度和高度。在清單中,我用了:Android中的橫向模式更改爲肖像

 <activity android:name=".MActivity" 
         android:label="@string/app_name" 
         android:screenOrientation="landscape" 
android:theme="@android:style/Theme.NoTitleBar" 
       android:configChanges="keyboardHidden|orientation"> 

而且在活動:

layout = (LinearLayout)findViewById(R.id.Rishikesh); 
     ViewTreeObserver vto = layout.getViewTreeObserver(); 
     vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 

      public void onGlobalLayout() { 
       int finalHeight, finalWidth; 
       finalHeight = layout.getMeasuredHeight(); 
       finalWidth = layout.getMeasuredWidth(); 
       Log.w("*************", "OnGlobalLayoutListener/ Footer height :"+layout.getHeight()+" Width :"+layout.getWidth()); 


      } 
     }); 

它使在橫向模式下的高度和寬度。但是,當我鎖定我的手機時,它會以縱向模式提供高度和寬度。我做錯了我不知道。我正在研究ANdroid 2.1。誰能幫我解決這個問題嗎?鎖定前

日誌:

08-11 15:19:08.996: INFO/NotificationService(1156): enqueueToast pkg=com.Timer [email protected] duration=100 
08-11 15:19:09.005: WARN/*************(2369): OnGlobalLayoutListener/ Footer height :442 Width :854 
08-11 15:19:09.995: INFO/NotificationService(1156): enqueueToast pkg=com.Timer [email protected] duration=100 
08-11 15:19:10.005: WARN/*************(2369): OnGlobalLayoutListener/ Footer height :442 Width :854 
08-11 15:19:10.335: DEBUG/dalvikvm(2075): GC freed 6414 objects/550768 bytes in 212ms 
08-11 15:19:10.345: ERROR/webcoreglue(2075): The real object has been deleted 
08-11 15:19:10.345: ERROR/webcoreglue(2075): The real object has been deleted 
08-11 15:19:10.345: ERROR/webcoreglue(2075): The real object has been deleted 
08-11 15:19:10.355: DEBUG/webviewglue(2075): nativeDestroy view: 0xa6bf48 
08-11 15:19:10.996: INFO/NotificationService(1156): enqueueToast pkg=com.Timer [email protected] duration=100 
08-11 15:19:10.996: WARN/*************(2369): OnGlobalLayoutListener/ Footer height :442 Width :854 
08-11 15:19:11.995: INFO/NotificationService(1156): enqueueToast pkg=com.Timer [email protected] duration=100 
08-11 15:19:11.995: WARN/*************(2369): OnGlobalLayoutListener/ Footer height :442 Width :854 
08-11 15:19:12.065: DEBUG/WindowManager(1156): I'm tired mEndcallBehavior=0x2 
08-11 15:19:12.295: INFO/power(1156): *** set_screen_state 0 

日誌:鎖定後:

08-11 15:19:12.315: DEBUG/WifiService(1156): ACTION_SCREEN_OFF 
08-11 15:19:12.325: DEBUG/SurfaceFlinger(1156): About to give-up screen, flinger = 0x11cf18 
08-11 15:19:12.385: DEBUG/ViewFlipper(1369): updateRunning() mVisible=false, mStarted=true, mUserPresent=false, mRunning=false 
08-11 15:19:12.585: DEBUG/dalvikvm(1156): GC freed 18364 objects/926968 bytes in 153ms 
08-11 15:19:12.725: INFO/WindowManager(1156): Setting rotation to 0, animFlags=0 
08-11 15:19:12.725: INFO/ActivityManager(1156): Start proc com.android.settings for broadcast com.android.settings/.widget.SettingsAppWidgetProvider: pid=2402 uid=1000 gids={3003, 1015, 3002, 3001} 
08-11 15:19:12.755: INFO/dalvikvm(2402): Debugger thread not active, ignoring DDM send (t=0x41504e4d l=38) 
08-11 15:19:12.765: INFO/ActivityManager(1156): Config changed: { scale=1.0 imsi=0/0 loc=en_IN touch=3 keys=1/1/2 nav=1/1 orien=1 layout=34} 
08-11 15:19:12.825: WARN/*************(2369): OnGlobalLayoutListener/ Footer height :816 Width :480 
08-11 15:19:12.885: INFO/dalvikvm(2402): Debugger thread not active, ignoring DDM send (t=0x41504e4d l=44) 
08-11 15:19:12.905: INFO/ActivityManager(1156): Process com.touchnote.android (pid 2382) has died. 

鎖定之前:OnGlobalLayoutListener /頁腳高度:442寬度:854 鎖定後:OnGlobalLayoutListener /頁腳高度:816寬度:480

回答

0

問題是您的應用程序不在前臺,其他應用程序可能請求允許縱向或僅縱向顯示。

您會收到當前的全局佈局 - 可能是肖像。可能你在屏幕鎖定之前收到onPause(),當你的應用程序返回到前臺時收到onResume() - 如果你不想在不在後臺時獲得佈局,只要使用bool存儲,如果你是前臺應用程序。

+0

實際上,當我第一次調用onGlobalLayout時,我必須將高度和寬度發送到服務器。當用戶在調用電話之前鎖定電話時,它將採用縱向模式的高度和寬度,如日誌中所示。我可以通過檢查foregroung來實現,但這是一個複雜的邏輯。有沒有辦法阻止這種方向的改變。它是一個錯誤還是其他的東西? – RiksAndroid

+0

嗨wojciechka,我必須發送數據,只要我的ap開始。所以,我不能應用這個邏輯。它不會改變爲肖像。當我們從電腦處於鎖定模式時啓動應用程序時,它處於橫向模式,但縱向顯示高度和寬度。 – RiksAndroid

1

刪除後檢查「android:configChanges="keyboardHidden|orientation"

+0

它仍然沒有工作。這裏是日誌。 – RiksAndroid

+0

對不起,在我的問題上面 – RiksAndroid

相關問題