How to structure the CN1 code for a tablet form layout?

蓝咒 提交于 2021-02-19 07:59:10

问题


I've been building my Codename One app for the phone screen format so far. There is a separate Form for the main menu, then a second Form with a list of elements, and then a third Form to edit an element selected from the list. Each Form has an overflow menu and various Titlebar command buttons. And each (Extended) Form has a lot of code that implements the functions in the Form and shares variables etc.

However, to use the tablet (iPad) screen estate, I would like to show the main menu on the left of the screen, the list of elements in the middle and the element edit form on the right. Something similar to the screenshot below. This seems to be a common type of layout on tablets and suits my app usage pattern well.

However, I don't see an elegant way of structuring the code to do this. I can't easily combine the list and edit Forms into one Form, and writing a completely new Form just for the tablet format would be a lot of work. I assume others have faced the same challenge and would love to hear how you achieved this.

PS. I know the side menu can be made permanent but that only solves part of the problem, not how to show a list and edit Forms at the same time.


回答1:


There is no one answer for this but if you look at apps like Codename One Build you would notice they adapt to this form factor.

We usually just use isTablet() to adapt the UI at key points to the different form factor. One element is the permanent side menu which we turn on in the init method using code like this:

if(Display.getInstance().isTablet()) {
    Toolbar.setPermanentSideMenu(true);
}

It makes the side menu stay open all the time. Within the code we try to use Container instead of Form. This allows us to package multiple logical pieces into a single UI for the tablet mode.



来源:https://stackoverflow.com/questions/54269508/how-to-structure-the-cn1-code-for-a-tablet-form-layout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!