lvgl bar

1. 创建bar对象

	//1 创建bar对象
	lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);

	//2 设置当前bar外观大小尺寸
	lv_obj_set_size(bar, 200, 30);

	//3 设置其在父类中为中心对齐
	lv_obj_align(bar, NULL, LV_ALIGN_IN_TOP_RIGHT, -80, 0);

	//4 设置其为1s变化一次
	//lv_bar_set_anim_time(bar, 1000);

	//5 设置其初始值为100,并可动态变化
	lv_bar_set_value(bar, 100, LV_ANIM_ON);

	//6 TODO:事件不生效,待查
	lv_obj_set_event_cb(bar, bar_event_handler); 

2. 事件(未生效,待查)

//描述:bar事件回调函数
static void bar_event_handler(lv_obj_t *obj, lv_event_t event)
{	
	if (event == LV_EVENT_PRESSED)
	{
		static int16_t value = 0;

		value = lv_bar_get_value(obj);
		if (value > 100)
			value = 0;
		else
			value += 10;

		//静态显示设置值
		lv_bar_set_value(obj, value, LV_ANIM_OFF);
	}
}

 

2. 效果图

おすすめ

転載: blog.csdn.net/chenliang0224/article/details/112165427