从lvgl v8版本开始,lvgl的obj默认开启了滚动条。

对于滚动条一般有三种需求:

  1. 保留滚动条,那就不用改变,默认是开启的滚动条,超出obj的部分可以滚动过去显示
  2. 禁用滚动条,obj不需要滚动
  3. 保留滚动条,不显示滚动条

第2种obj实现:

    lv_obj_t * obj = lv_obj_create(desktop_app.bg_win);
    lv_obj_set_pos(obj, 20, 380);
    lv_obj_set_size(obj, 400, 100);
    // lv_obj_set_style_bg_color(obj, lv_color_hex(0x1F1F1F), 0);
    lv_obj_t *label = lv_label_create(obj);
    lv_label_set_text(label, "I am fine....hsahhhhhhhhhhhhhhaaaaaaaaaaaaaaaaaaaaaaaaaaaahnnnngj");
    // lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_set_scroll_dir(obj, LV_DIR_HOR);
    
    lv_obj_set_style_bg_color(obj, lv_color_hex(0x1F1F1F), 0);
    lv_obj_set_style_text_color(obj, lv_color_hex(0xFFFFFF), 0);
  • lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE); 禁用滚动条
  • lv_obj_set_scroll_dir(obj, LV_DIR_VER); 设置滚动方向,LV_DIR_HOR水平滚动LV_DIR_VER垂直滚动

第3种obj实现:

    lv_obj_t * obj = lv_obj_create(desktop_app.bg_win);
    lv_obj_set_pos(obj, 20, 380);
    lv_obj_set_size(obj, 400, 100);
    // lv_obj_set_style_bg_color(obj, lv_color_hex(0x1F1F1F), 0);
    
    lv_obj_t *label = lv_label_create(obj);
    lv_label_set_text(label, "I am fine....hsahhhhhhhhhhhhhhaaaaaaaaaaaaaaaaaaaaaaaaaaaahnnnngj");
    lv_obj_set_scroll_dir(obj, LV_DIR_HOR);
    
    lv_obj_set_style_bg_opa(obj, LV_OPA_0, LV_PART_SCROLLBAR | LV_STATE_DEFAULT);
    lv_obj_set_style_bg_opa(obj, LV_OPA_0, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);

    lv_obj_set_style_bg_color(obj, lv_color_hex(0x1F1F1F), 0);
    lv_obj_set_style_text_color(obj, lv_color_hex(0xFFFFFF), 0);
  • lv_obj_set_style_bg_opa(obj, LV_OPA_0, LV_PART_SCROLLBAR | LV_STATE_DEFAULT),设置样式将obj滚动条的颜色默认为透明,
  • lv_obj_set_style_bg_opa(obj, LV_OPA_0, LV_PART_SCROLLBAR | LV_STATE_SCROLLED),设置样式将obj滚动条滚动时的颜色也设置为透明
  • 在这里插入图片描述
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐