源代码:
static void roller_event_handler(lv_obj_t * obj, lv_event_t event)
{
if (event == LV_EVENT_VALUE_CHANGED) {
char buf[32];
lv_roller_get_selected_str(obj, buf, sizeof(buf));
printf("Selected month: %s\n", buf);
}
}
//21 滚动对象
//21.1 创建一个滚动对象
lv_obj_t *roller1 = lv_roller_create(lv_scr_act(), NULL);
lv_roller_set_options(roller1,
"1.January\n"
"2.February\n"
"3.March\n"
"4.April\n"
"5.May\n"
"6.June\n"
"7.July\n"
"8.August\n"
"9.September\n"
"10.October\n"
"11.November\n"
"12.December",
LV_ROLLER_MODE_INIFINITE);
//21.2 设置可见的行个数
lv_roller_set_visible_row_count(roller1, 4);
lv_roller_set_align(roller1, LV_LABEL_ALIGN_LEFT);
lv_obj_align(roller1, NULL, LV_ALIGN_CENTER, 180, 220);
lv_obj_set_event_cb(roller1, roller_event_handler);
效果演示: