c++ - 同步 : Why wont this display my Layout

标签 c++ mobile layout

我正在研究布局并试图了解它们的工作原理。布局是否类似于 Java Swing 中的 JPanel?即,我们在哪里声明主面板并将所有小部件添加到其中?

我不明白的一件事是,当我们创建一个移动应用程序时,我们创建了一个布局和一个列表框。这两个对象之间的关系是什么?

  • Layout 对象是否包含列表框,然后我们将所有小部件添加到列表框?
  • 或者列表框是否定义了布局,然后我们将小部件添加到列表框并根据布局对齐
  • 还是像 Java Swing 一样将所有小部件添加到布局中?

PS:我下面的实验,我的小部件没有显示?它只是一个空白的黑屏。为什么会这样?

#include <MAUtil/Moblet.h>
#include <MAUI/Layout.h>
#include <MAUI/ListBox.h>
#include <MAUI/Label.h>
#include <MAUI/EditBox.h>
#include <MAUI/Screen.h>
#include <MAUtil/Environment.h>
#include <madmath.h>
#include <conprint.h>


using namespace MAUtil;
using namespace MAUI;

class TemperatureScreen : public Screen  //, public PointerListener
{
    public:
        TemperatureScreen()
        {
            MAExtent screenDim = maGetScrSize();
            Layout* mainLayout  = new Layout( 0, 0, EXTENT_X(screenDim), EXTENT_Y(screenDim), NULL, 1, 3 );
            ListBox* mainListBox = new ListBox( 0, 0, 100, 200, mainLayout,
                                       ListBox::LBO_VERTICAL, ListBox::LBA_LINEAR,
                                       true );
            mainListBox -> setPaddingLeft( 10 );
            mainListBox -> setPaddingRight( 10 );
            mainListBox -> setPaddingTop( 10 );
            mainListBox -> setPaddingBottom( 10 );
            mainListBox -> setBackgroundColor( 900 );
            mainLayout  -> setBackgroundColor( 300 );

            Label *celLabel     = new Label( 10, 300, 50, 20, mainLayout );
            Label *fahLabel     = new Label( 10, 300, 50, 20, mainLayout );
            EditBox *celEdit    = new EditBox( 10, 300, 50, 20, mainLayout );
            EditBox *fahEdit    = new EditBox( 10, 300, 50, 20, mainLayout );
            Label *toCelsiusRb  = new Label( 10, 300, 50, 20, mainLayout );
            Label *toFahRb      = new Label( 10, 300, 50, 20, mainLayout );
            Label *convertLabel = new Label( 10, 300, 50, 20, mainLayout );
            Label *exitLabel    = new Label( 10, 300, 50, 20, mainLayout );

            celLabel     -> setCaption( "Celcius" );
            fahLabel     -> setCaption( "Fahrenheit" );
            convertLabel -> setCaption( "Convert" );
            exitLabel    -> setCaption( "Exit" );
            /*celLabel   -> addPointerListener( this );
            fahLabel     -> addPointerListener( this );
            convertLabel -> addPointerListener( this );
            exitLabel    -> addPointerListener( this );*/

            mainLayout -> add( celLabel );
            mainLayout -> add( fahLabel );
            mainLayout -> add( convertLabel );
            mainLayout -> add( exitLabel );
        }

};

class TemperatureMoblet : public Moblet
{
    public:
        TemperatureMoblet()
        {
            instance = new TemperatureScreen();
            instance -> show();
        }

        ~TemperatureMoblet()
        {
            delete instance;
        }

        void keyPressEvent(int keyCode, int nativeCode)
        {
            // todo: handle key presses
            printf( "Blah" );
        }

        void keyReleaseEvent(int keyCode, int nativeCode)
        {
            // todo: handle key releases
        }

    private:
        TemperatureScreen *instance;
};

extern "C" int MAMain()
{
    Moblet::run(new TemperatureMoblet());
    return 0;
};

最佳答案

尝试将 maUpdateScreen() 放入计时器事件或关键监听器中,看看会发生什么。

如果您需要更多帮助,请回复我。

您可以在以下位置试用 mosync 的新版本 2.6:

http://www.mosync.com/documentation/manualpages/whats-new-mosync-26-pyramid

/托尼

关于c++ - 同步 : Why wont this display my Layout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5253665/

相关文章:

c++ - 推荐跨平台 C++ GUI 和网络库

c++ - 为什么未初始化的全局变量是弱符号?

html - CSS 标题布局

html - 如何正确对齐此 html 布局?

c++ - 代码已退出-1073741515(0xc0000135) 'A dependent dll was not found'

c++ - 我很难理解指针

html - 仅在台式机上显示 adsense 广告并在手机上隐藏它

mobile - 查询对象 where 函数过滤器

ios - Flutter 我想把界面设计成这样,大家能帮帮我吗?我正在设计一个关于页面,但我遇到了问题

android - 如何创建标准的无边框按钮(如提到的设计指南中)?