コード例 #1
0
Vector<Widget*> MainPage::createWidgets() {
    RelativeController* plc = NULL;;
    TextWidget* txt = NULL;
    Button* btn = NULL;
    ImageWidget* img = NULL;

    RelativeControllerParams imgParams(ControllerParams::MATCH_PARENT, ControllerParams::MATCH_PARENT);

    RelativeControllerParams button(ControllerParams::WRAP_CONTENT, ControllerParams::WRAP_CONTENT);
    button.setRelation(RelativeControllerParams::ALIGN_PARENT_BOTTOM);
    button.setRelation(RelativeControllerParams::ALIGN_PARENT_LEFT);

    RelativeControllerParams text(ControllerParams::WRAP_CONTENT, ControllerParams::WRAP_CONTENT);
    text.setRelation(RelativeControllerParams::CENTER_IN_PARENT);

    Vector<Widget*> widgets;
    for (size_t i = 0; i < 10; i++) {
        plc = new RelativeController(this);
        mWidgetPool.append(plc);

        img = new ImageWidget(this);
        mWidgetPool.append(img);
        img->setImageResource(gPictures[i]);
        img->setScaleType(ImageWidget::FIT_XY);
        plc->addWidget(img);
        img->setControllerParams(&imgParams);

        txt = new TextWidget(this);
        txt->setControllerParams(&text);
        mWidgetPool.append(txt);
        txt->setText(String::format("this is %d picture.", i + 1));
        txt->setTextColor(0xffff0000);
        plc->addWidget(txt);

        btn = new Button(this);
        btn->setControllerParams(&button);
        mWidgetPool.append(btn);
        btn->setText(String::format("button %d", i+1));
        plc->addWidget(btn);

        widgets.append(plc);
    }
    GLOG(LOG_TAG, LOGINFO, "widgets size %d", widgets.size());
    return widgets;
}