在 Java ME 中,如何更改 MIDlet 显示内容的方向,使其从右向左?
我的 Java ME MIDlet 允许用户更改 Midlet 的语言。
我的代码处理国际化,对于从左到右的语言来说它工作得很好。
但是,当用户将语言更改为从右到左的语言时,会显示正确的字符串,但屏幕仍保持左对齐。
换句话说,手机的区域设置是 en_US,我不想更改它。
我只想更改我的 MIDlet 的区域设置。
动态更改 MIDlet 的所有屏幕以右对齐其内容的最简单方法是什么?
我不介意解决方案是否涉及让用户重新启动应用程序。
如果没有 Java ME 解决方案,我也不介意该解决方案是否是诺基亚手机专有的。
My Java ME MIDlet allows its user to change the language of the Midlet.
My code handles the internationalization, and it works fine for left-to-right languages.
But when the user changes the language to Right-To-Left language, the correct strings are being displayed but the screens remain left-justified.
In other words, the phone's locale is en_US and I don't want to change it.
I just want to change my MIDlet's locale.
What's the simplest way to dynamically change all the screens of the MIDlet to right-justify their content?
I don't mind if the solution involves having the user restart the application.
I also don't mind if the solution is proprietary to Nokia phones if there is no Java ME solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您使用的是 LCDUI,默认情况下,
StringItems
等将根据手机的区域设置获得默认布局。即Item.LAYOUT_DEFAULT
,这意味着具有en_US
区域设置的手机将从左到右显示项目,而具有ar_EG
区域设置的手机将显示文本从右到左。但是,可以使用
setLayout()
函数强制布局右对齐文本:您可以轻松创建一个单例
Settings
类,该类可以保存一个带有用于对齐的值的标志(Item.LAYOUT_LEFT
或Item.LAYOUT_RIGHT
),并在设置布局时调用它,例如:这也可以在构造函数如果你 希望。
对于低级
Graphics
,可以使用drawString()
方法并更改文本的方向,但您需要从右上角计算起点文本不是左上角最简单的解决方案(您已经拒绝了)是在整个过程中使用
Item.LAYOUT_DEFAULT
并更改手机的区域设置(当然),但您仍然需要使用覆盖drawString()
如果您使用低级图形。为了检查正确的理由,我将使用 System.getProperty("microedition.locale") 将输入区域设置输入到如下函数中:
Assuming you are using LCDUI, by default
StringItems
and so on will be given a default layout based on the phone's locale. i.e.Item.LAYOUT_DEFAULT
, this means a phone with anen_US
locale will display items left to right whereas a phone with anar_EG
locale will display texts right to left.It is however possible to force the layout to right justify texts using the
setLayout()
function:You could easily create a singleton
Settings
class, which could hold a flag with the value to use for justification (Item.LAYOUT_LEFT
orItem.LAYOUT_RIGHT
), and call it when setting the layout e.g.:This could also be done in the constructor if you wish.
For low level
Graphics
thedrawString()
method can be used and the direction of the text altered, but you'll need to calculate the start point from the top right of your text not the top leftThe simplest solution (which you have already rejected) would be to use
Item.LAYOUT_DEFAULT
throughout and alter the locale of the phone (of course), but you will still need to use an override fordrawString()
if you use low level graphics.To check the correct justification I would enter the input locale using
System.getProperty("microedition.locale")
into a function such as this: