2011-10-17 28 views
2

我給黑莓風暴製作代碼。當我的橫向顯示應用程序(480x360),它的工作。但是,當黑莓傾斜到垂直(360x480)時,照片被切斷。所以我問如何設置,以便在旋轉時調整圖片大小?有沒有什麼方法可以檢查黑莓手機是否再次水平或垂直顯示?黑莓編程自動旋轉

謝謝。

回答

6

以下是兩件事情,要麼鎖定屏幕方向,要麼在您的應用程序中支持。

代碼示例:檢索屏幕方向

switch(Display.getOrientation()) 
{ 
    case Display.ORIENTATION_LANDSCAPE: 
     Dialog.alert("Screen orientation is landscape"); break; 
    case Display.ORIENTATION_PORTRAIT: 
     Dialog.alert("Screen orientation is portrait"); break; 
    case Display.ORIENTATION_SQUARE: 
     Dialog.alert("Screen orientation is square"); break; 
    default: 
     Dialog.alert("Screen orientation is not known"); break; 
} 

代碼示例:強制縱向視圖在BlackBerry API應用程序

// Use code like this before invoking UiApplication.pushScreen() 
int direction = Display.DIRECTION_NORTH; 
Ui.getUiEngineInstance().setAcceptableDirections(direction); 

你要處理的圖像和其他圖形設置在方向更改上,您可以在代碼中進行以下更改。

  1. 覆蓋MainScreen子類中的sublayout方法。

    protected void sublayout(int arg0,int arg1){ //完成所有 super.sublayout(arg0,arg1); }

  2. 檢查方向更改,重新排列UI。推薦使用相對佈局來實現這種功能。

希望,這可能會幫助你。欲瞭解更多信息請訪問Specifying_display_direction_of_screen

編輯:覆蓋sublayout(),然後編寫代碼的具體取向

public void sublayout(int width, int height) { 
    switch(Display.getOrientation()) 
     { 
      case Display.ORIENTATION_LANDSCAPE: 
       // write the piece of code for refreshing the screen UI which screen orientation is landscape 
       break; 
      case Display.ORIENTATION_PORTRAIT: 
       // write the piece of code for refreshing the screen UI which screen orientation is portrait 
       break; 

     } 
    super.sublayout(width, height); 
} 

編輯2:

你要因爲UI事件鎖定的錯誤,現在您對代碼進行了以下更改。

public void sublayout(int maxWidth, int maxHeight) { 
      int displayWidth = deviceWidth; 
      int displayHeight = deviceHeight; 

      switch (Display.getOrientation()) { 
      case Display.ORIENTATION_LANDSCAPE: 
       UiApplication.getUiApplication().invokeLater(new Runnable() 
       { 
        public void run() 
        { 
         Dialog.alert("Screen orientation is landscape"); 
         // here you need to change your uI code as you want to do in for landscape mode 
         // you may need to delete and add the UI comps manually 
         // if the components added to absolute layout then just refresh the screen it will auto adjust with your new screen size 
        } 
       }); 

       break; 
      case Display.ORIENTATION_PORTRAIT: 
       UiApplication.getUiApplication().invokeLater(new Runnable() 
       { 
        public void run() 
        { 
         Dialog.alert("Screen orientation is PORTRAIT:"); 
         // here you need to change your uI code as you want to do in for PORTRAIT mode 
         // you may need to delete and add the UI comps manually 
         // if the components added to absolute layout then just refresh the screen it will auto adjust with your new screen size 

        } 
       }); 
       break; 
      } 
      super.sublayout(displayWidth, displayHeight); 
      setExtent(displayWidth, displayHeight); 
     } 
+0

我喜歡在我的應用程序支持。我現在就試一試。非常感謝。 =) –

+0

按照可以幫助你做同樣的步驟。 –

+0

@ And1 Siahaan ..檢查編輯部分。 –

0

那麼我之前遇到過這個問題並解決了它。解決方案不是「強制黑莓屏幕不旋轉」。我之前做過這個,很煩人。那麼解決方案是覆蓋主屏幕的subLayout方法和主屏幕中包含的所有管理器。發生旋轉時總是調用此方法。

你的代碼將看起來像如下:

public void sublayout(int width, int height) { 
    changeImage(); // this method will change your image x and y and then draw it again 
    super.sublayout(width, height); 
} 
+0

重複相同的答案.. –