2011-03-09 40 views
1

我钻研布局&试图了解他们的工作。布局是否像Java Swing中的JPanel一样?也就是说,我们在哪里宣布主面板&将所有小部件添加到此?Mosync:为什么惯于此显示我的布局

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

  • Layout对象是否包含Listbox,那么我们将所有的小部件添加到列表框?
  • 抑或列表框有一个布局定义,那么我们根据布局
  • 小部件添加到它们对齐列表框&还是我们中的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; 
}; 

回答

相关问题