如何将标签垂直居中?

时间:2016-08-08 16:33:56

标签: tizen tizen-wearable-sdk tizen-native-app

我正在为Samsung Gear(Tizen)开发本机应用程序。 我有一个动态生成的多行标签(可以有2或3行)。 我怎样才能垂直居中?

1 个答案:

答案 0 :(得分:2)

使用Elementary Box容器。 它将孩子们放在垂直中间。

这是示例代码。在app_create函数中引用box和3标签的代码。

#include <sstream>

#include <app.h>
#include <Elementary.h>
#include <efl_extension.h>

static bool app_create(void *data)
{
    Evas_Object *win = elm_win_util_standard_add("sample", "sample");
    elm_win_autodel_set(win, EINA_TRUE);

    if (elm_win_wm_rotation_supported_get(win)) {
        int rots[4] = { 0, 90, 180, 270 };
        elm_win_wm_rotation_available_rotations_set(win, (const int *)(&rots), 4);
    }

    auto back_cb = [](void *data, Evas_Object *obj, void *event_info) {
        elm_win_lower(static_cast<Evas_Object*>(data));
    };

    evas_object_smart_callback_add(win, "delete,request",
            [](void*, Evas_Object*, void*){ui_app_exit();}, NULL);
    eext_object_event_callback_add(win, EEXT_CALLBACK_BACK, back_cb, win);

    Evas_Object *conform = elm_conformant_add(win);
    elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW);
    elm_win_indicator_opacity_set(win, ELM_WIN_INDICATOR_OPAQUE);
    evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    elm_win_resize_object_add(win, conform);
    evas_object_show(conform);

    Evas_Object *box = elm_box_add(conform);
    evas_object_show(box);
    elm_object_content_set(conform, box);

    Evas_Object *labels[3];

    for (int i=0; i<3; i++)
    {
        std::ostringstream ss;
        ss << "<align=center>line : " << i << "</align>";
        labels[i] = elm_label_add(box);
        elm_object_text_set(labels[i], ss.str().c_str());
        evas_object_show(labels[i]);
        elm_box_pack_end(box, labels[i]);
    }

    evas_object_show(win);
    return true;
}


int main(int argc, char *argv[])
{
    ui_app_lifecycle_callback_s event_callback = {
            app_create, nullptr, nullptr, nullptr, nullptr
    };
    return ui_app_main(argc, argv, &event_callback, nullptr);
}