API接口:
1、设置对齐模式:
void lv_obj_set_style_text_align(struct _lv_obj_t * obj, lv_text_align_t value, lv_style_selector_t
selector);
支持三种对齐模式:
/** Label align policy*/
enum {
LV_TEXT_ALIGN_AUTO, /**< Align text auto*/
LV_TEXT_ALIGN_LEFT, /**< Align text to left*/
LV_TEXT_ALIGN_CENTER, /**< Align text to center*/
LV_TEXT_ALIGN_RIGHT, /**< Align text to right*/
};
typedef uint8_t lv_text_align_t;
例程 :
static void _create_label_obj(void)
{
lv_obj_t *lable = lv_label_create(lv_scr_act());
lv_label_set_long_mode(lable, LV_LABEL_LONG_WRAP);//部分长模式下lv_obj_set_size无效
lv_label_set_text(lable, "test create lable");
// lv_obj_align(pobj[i], LV_ALIGN_CENTER, 0, 0);
lv_obj_set_pos(lable, 100, 120);
// lv_obj_set_size(pobj[i], 100, 40);
lv_obj_set_width(lable, 150); /*Set smaller width to make the lines wrap*/
// lv_obj_set_style_text_font(lable, font_montserrat_32, 0);
lv_obj_set_style_text_color(lable, lv_color_white(), 0);
lv_obj_set_style_bg_color(lable, lv_palette_main(LV_PALETTE_RED), 0);
lv_obj_set_style_bg_opa(lable, 255, 0);
lv_obj_set_style_base_dir(lable, LV_BASE_DIR_LTR, 0);//设置文本内容绘制方向,从左到右?
lv_obj_set_style_text_align(lable, LV_TEXT_ALIGN_CENTER, 0);//设置文本对齐方式
}
运行效果: