2016-08-08 102 views
0

我正在爲三星齒輪(Tizen)開發原生應用程序。 我有一個多行標籤動態生成(可以有2或3行)。 如何垂直居中?如何垂直放置標籤?

+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); 
}