And*_*aan 2 blackberry rotation
我为Blackberry Storm制作代码.当我的应用程序在水平显示(480x360)时,它的工作.但当黑莓倾斜到垂直(360x480)时,图片被切断了.所以我问如何设置,以便在轮换时,还调整图片大小?有没有办法检查黑莓再次水平或垂直显示?
谢谢.
这里有两件事,要么您将锁定屏幕方向,要么您将在您的应用程序中支持.
代码示例:检索屏幕方向
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;
}
Run Code Online (Sandbox Code Playgroud)
代码示例:在BlackBerry API应用程序中强制纵向视图
// Use code like this before invoking UiApplication.pushScreen()
int direction = Display.DIRECTION_NORTH;
Ui.getUiEngineInstance().setAcceptableDirections(direction);
Run Code Online (Sandbox Code Playgroud)
您想要在方向更改时处理图像和其他图形设置,然后您可以在代码中进行以下更改.
在MainScreen子类中重写sublayout方法.
protected void sublayout(int arg0,int arg1){//执行所有super.sublayout(arg0,arg1); }
检查方向更改,重新排列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);
}
Run Code Online (Sandbox Code Playgroud)
编辑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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2010 次 |
| 最近记录: |