2011-07-14 32 views

回答

1

當這種情況發生時,BB UI框架definitelly調用layout(int width, int height)爲您的屏幕。這是因爲MainScreen也是Manager,因此它應該在BB UI框架開始繪製之前佈置其所有子字段。

因此,在layout()中,您可以跟蹤當前的方向狀態(使用net.rim.device.api.system.Display.getOrientation())並與之前的狀態進行比較。如果它改變了,那麼設備剛旋轉。

+0

但我們不能優先佈局()在MainScreen功能。在BB開發站點,他們表示:當觸摸屏的方向改變時接收通知導入net.rim.device.api.ui.Manager類。覆蓋net.rim.device.api.ui.Manager.sublayout(int,int)。 protected void sublayout(int width,int height){.. 我做了,但是當我旋轉屏幕時模擬器沒有運行到代碼。我不是這是一個模擬器問題或什麼。 無論如何,感謝 –

+1

Torch 9800的行爲可能會有所不同,具體取決於其滑桿是否打開或關閉。可能只是嘗試打開/關閉滑塊。 –

0

我想出了一種不同於Arhimed建議的方法,它似乎很好用(我用它來繪製自定義字段 - 當設備傾斜時)。我有一個方法

protected void myOrientation() { 
    // portrait is true when dh > dw 
    boolean portrait = (Display.getOrientation() == Display.ORIENTATION_PORTRAIT); 
    // dw and dh = real horizontal and vertical dimensions of display - regardless of device orientation 
    int dw = portrait ? Math.min(Display.getWidth(), Display.getHeight()) : Math.max(Display.getWidth(), Display.getHeight()); 
    int dh = portrait ? Math.max(Display.getWidth(), Display.getHeight()) : Math.min(Display.getWidth(), Display.getHeight()); 

    // here I draw my custom Field 

    invalidate(); 
} 

,並在構造函數中調用它一次,它被稱爲在每個加速度事件之後:

public class MyScreen extends MainScreen implements AccelerometerListener { 

private MyScreen() { 
    if (AccelerometerSensor.isSupported()) { 
     orientationChannel = AccelerometerSensor.openOrientationDataChannel(Application.getApplication()); 
     orientationChannel.addAccelerometerListener(this); 
    } 
    .... 
} 


public void onData(AccelerometerData accData) { 
    if (old != accData.getOrientation()) { 
     myField.myOrientation(); 
    } 
} 

也許這可以幫助你,是的 - 你必須檢查,如果鍵盤滑出在火炬

問候 亞歷