簡體   English   中英

Android:始終以縱向啟動“活動”,但可以識別方向變化

[英]Android: start Activity always in portrait but recognize orientation change

我想始終以縱向方向開始新的活動/意圖(即使設備橫向放置)

如果我使用setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 活動被鎖定為人像,但我想識別方向的變化。

所以我想我必須打電話給setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 在第一次創建活動時,需要一個偵聽器來消除此限制。

但是我應該用哪種方法呢? 在構造函數中,還是在onCreate()或其他地方???

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        // TODO Auto-generated method stub
        super.onConfigurationChanged(newConfig);

        System.out.println("on config change method called.");

        if(Configuration.ORIENTATION_LANDSCAPE==newConfig.orientation)
        {

                    //Portatrate to landscape...
            System.out.println("on config change method called portraite mode.");
        }
        else if(Configuration.ORIENTATION_PORTRAIT==newConfig.orientation)
        {
            //Landscape to portraite....
            System.out.println("on config change method called landscape mode.");
        }
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM