在Android中,横向模式更改为纵向

时间:2011-08-11 11:29:15

标签: android landscape-portrait

我有一个计时器应用程序,我的应用程序应始终处于LandScape模式。我在代码中获得了主要布局的宽度和高度。在清单中,我使用过:

     <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 callback=android.app.ITransientNotification$Stub$Proxy@45b190a0 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 callback=android.app.ITransientNotification$Stub$Proxy@45a6b670 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 callback=android.app.ITransientNotification$Stub$Proxy@45a63ed0 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 callback=android.app.ITransientNotification$Stub$Proxy@45afcbe0 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

2 个答案:

答案 0 :(得分:1)

删除“android:configChanges="keyboardHidden|orientation"

后检查

答案 1 :(得分:0)

问题是您的应用程序不在前台,其他应用程序可能会请求允许纵向或仅纵向。

您会收到当前的全局布局 - 可能是肖像。你可能会在屏幕被锁定之前收到onPause(),当你的应用程序回到前台时你会收到onResume() - 如果你不想在不在后台时获得布局,如果你是前台应用程序,只需使用bool来存储。