屏幕上创建个page, 然后page上面垂直方向放多个cont, 超过屏幕大小,page可以上下滑动查看cont列表, 但是如果给屏幕添加左右手势, page上下滑动就会卡顿
可能是硬件资源问题,请给出你的关键代码以及运行现象。
static void features_event_cb(lv_obj_t *obj, lv_event_t event)
{
switch (event)
{
case LV_EVENT_GESTURE:
{
lv_indev_wait_release(lv_indev_get_act());
lv_gesture_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
if (dir == LV_GESTURE_DIR_RIGHT)
{
junp_to_screen(MAIN_SCREEN);
}
}
break;
default:
break;
}
}
void main(void)
{
featureMenuScreen.features_screen = lv_obj_create(NULL, NULL);
lv_scr_load_anim(featureMenuScreen.features_screen, LV_SCR_LOAD_ANIM_NONE, 0, 0, true);
lv_obj_t *feature_page = lv_page_create(featureMenuScreen.features_screen, NULL);
lv_obj_clean_style_list(feature_page, LV_OBJ_PART_MAIN);
lv_obj_set_style_local_bg_opa(feature_page, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_100);
lv_obj_set_style_local_bg_color(feature_page, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_size(feature_page, 320, 360);
lv_obj_set_pos(feature_page, 0, 0);
lv_obj_t *cont1 = lv_cont_create(feature_page, NULL);
lv_obj_set_style_local_bg_color(cont1 , LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_size(cont1, 260, 40);
lv_obj_align(cont1, feature_page, LV_ALIGN_IN_TOP_MID, 0, 10);
lv_obj_t *label = lv_label_create(cont1, NULL);
lv_label_set_align(label, LV_ALIGN_CENTER);
lv_label_set_text (label, "labe1");
lv_obj_set_style_local_text_color (label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_text_font (label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_PingFang_S_20);
lv_obj_t *cont2 = lv_cont_create(feature_page, NULL);
lv_obj_set_style_local_bg_color(cont2 , LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_size(cont2, 260, 40);
lv_obj_align(cont2, cont1, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_obj_t *labe2 = lv_label_create(cont2, NULL);
lv_label_set_align(labe2, LV_ALIGN_CENTER);
lv_label_set_text (labe2, "labe2");
lv_obj_set_style_local_text_color (labe2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_text_font (labe2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_PingFang_S_20);
lv_obj_t *cont3 = lv_cont_create(feature_page, NULL);
lv_obj_set_style_local_bg_color(cont3 , LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_size(cont3, 260, 40);
lv_obj_align(cont3, cont2, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_obj_t *labe3 = lv_label_create(cont3, NULL);
lv_label_set_align(labe3, LV_ALIGN_CENTER);
lv_label_set_text (labe3, "labe3");
lv_obj_set_style_local_text_color (labe3, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_text_font (labe3, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_PingFang_S_20);
lv_obj_t *cont4 = lv_cont_create(feature_page, NULL);
lv_obj_set_style_local_bg_color(cont4 , LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_size(cont4, 260, 40);
lv_obj_align(cont4, cont3, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_obj_t *labe4 = lv_label_create(cont4, NULL);
lv_label_set_align(labe4, LV_ALIGN_CENTER);
lv_label_set_text (labe4, "labe4");
lv_obj_set_style_local_text_color (labe4, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_text_font (labe4, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_PingFang_S_20);
lv_obj_t *cont5 = lv_cont_create(feature_page, NULL);
lv_obj_set_style_local_bg_color(cont5 , LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_size(cont5, 260, 40);
lv_obj_align(cont5, cont4, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_obj_t *labe5 = lv_label_create(cont5, NULL);
lv_label_set_align(labe5, LV_ALIGN_CENTER);
lv_label_set_text (labe5, "labe5");
lv_obj_set_style_local_text_color (labe5, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_text_font (labe5, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_PingFang_S_20);
lv_obj_t *cont6 = lv_cont_create(feature_page, NULL);
lv_obj_set_style_local_bg_color(cont6 , LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_size(cont6, 260, 40);
lv_obj_align(cont6, cont5, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_obj_t *labe6 = lv_label_create(cont6, NULL);
lv_label_set_align(labe6, LV_ALIGN_CENTER);
lv_label_set_text (labe6, "labe6");
lv_obj_set_style_local_text_color (labe6, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_text_font (labe6, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_PingFang_S_20);
lv_obj_t *cont7 = lv_cont_create(feature_page, NULL);
lv_obj_set_style_local_bg_color(cont7 , LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_size(cont7, 260, 40);
lv_obj_align(cont7, cont6, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_obj_t *labe7 = lv_label_create(cont7, NULL);
lv_label_set_align(labe7, LV_ALIGN_CENTER);
lv_label_set_text (labe7, "labe7");
lv_obj_set_style_local_text_color (labe7, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_text_font (labe7, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_PingFang_S_20);
lv_obj_t *cont8 = lv_cont_create(feature_page, NULL);
lv_obj_set_style_local_bg_color(cont8 , LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_size(cont8, 260, 40);
lv_obj_align(cont8, cont7, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_obj_t *labe8 = lv_label_create(cont8, NULL);
lv_label_set_align(labe8, LV_ALIGN_CENTER);
lv_label_set_text (labe8, "labe8");
lv_obj_set_style_local_text_color (labe8, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_text_font (labe8, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_PingFang_S_20);
lv_obj_t *cont9 = lv_cont_create(feature_page, NULL);
lv_obj_set_style_local_bg_color(cont9 , LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_size(cont9, 260, 40);
lv_obj_align(cont9, cont8, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_obj_t *labe9 = lv_label_create(cont9, NULL);
lv_label_set_align(labe9, LV_ALIGN_CENTER);
lv_label_set_text (labe9, "labe9");
lv_obj_set_style_local_text_color (labe9, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_text_font (labe9, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_PingFang_S_20);
lv_obj_t *cont10 = lv_cont_create(feature_page, NULL);
lv_obj_set_style_local_bg_color(cont10 , LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_size(cont10, 260, 40);
lv_obj_align(cont10, cont9, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_obj_t *labe10 = lv_label_create(cont10, NULL);
lv_label_set_align(labe10, LV_ALIGN_CENTER);
lv_label_set_text (labe10, "labe10");
lv_obj_set_style_local_text_color (labe10, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_obj_set_style_local_text_font (labe10, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_PingFang_S_20);
lv_obj_set_event_cb(featureMenuScreen.features_screen, features_event_cb);
}
每次滑动都进入了 features_event_cb 中并且会执行 LV_EVENT_GESTURE 中对手势的检测,是比较耗费资源的,建议你升级lvgl版本,v8中有针对智能手表的组件 tileview 了解地址: http://lvgl.100ask.net/8.2/widgets/extra/tileview.html#example
目前升级版本成本较大, 如果这么去做列表,有没有什么方式可以避免这种情况?
v7.11 就已经有 tileview,建议使用 tileview 而不是自己处理手势。
同时不要创建这么多 lv_cont_create ,优化参考: http://lvgl.100ask.net/8.2/widgets/core/table.html#lightweighted-list-from-table
tileview 阅读: