hhp
1
if (child_y_center == cont_y_center)
{
/* 当前显示界面的索引 */
lv_coord_t current_btn_index = lv_obj_get_index(child);
/* 判断界面移动的数数据,并将当前界面的索引改为中间位置 */
/* 因为是在滑动结束后实现的,建议界面较多的情况下使用此方式,当界面较少,一次滑动太多界面时,容易滑倒边界出现卡顿现象 */
lv_coord_t move_btn_quantity = LV_ABS(current_btn_index - mid_btn_index);
eLIBs_printf("move_btn_quantity%d\n", lv_obj_is_scrolling(cont));
flag_scroll_a = 1;
for (lv_coord_t j = 0; j < move_btn_quantity; j++)
{
/* 向右滑动 */
if (current_btn_index < mid_btn_index)
{
lv_obj_move_to_index(lv_obj_get_child(cont, child_cnt - 1), 0); // 将最后一个界面索引改为第一个界面
lv_obj_scroll_to_view(lv_obj_get_child(cont, mid_btn_index), LV_ANIM_OFF); // lv_obj_get_child 通过子索引获取对象的子对象
}
/* 向左滑动 */
if (current_btn_index > mid_btn_index)
{
lv_obj_move_to_index(lv_obj_get_child(cont, 0), child_cnt - 1); // 将第一个界面的索引值改为最后一个界面
lv_obj_scroll_to_view(lv_obj_get_child(cont, mid_btn_index), LV_ANIM_OFF); // lv_obj_get_child 通过子索引获取对象的子对象
}
}
Hi,
Please write in English. Using a translator is fine too.
100ask
3
Code
I’m not sure what effect you want, this is a reference(based on v8 version):
{
lv_obj_t * tabview;
tabview = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 50);
lv_obj_add_event_cb(lv_tabview_get_content(tabview), scroll_begin_event, LV_EVENT_SCROLL_END, NULL);
}
static void scroll_begin_event(lv_event_t * e)
{
lv_obj_t * cont = lv_event_get_target(e);
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * tv = lv_obj_get_parent(cont);
if(lv_event_get_code(e) == LV_EVENT_SCROLL_END) {
lv_tabview_t * tabview = (lv_tabview_t *)tv;
lv_coord_t s = lv_obj_get_scroll_x(cont);
lv_point_t p;
lv_obj_get_scroll_end(cont, &p);
lv_coord_t w = lv_obj_get_content_width(cont);
lv_coord_t t;
if(lv_obj_get_style_base_dir(tv, LV_PART_MAIN) == LV_BASE_DIR_RTL) t = -(p.x - w / 2) / w;
else t = (p.x + w / 2) / w;
if(s < 0) t = tabview->tab_cnt - 1;
else if((t == (tabview->tab_cnt - 1)) && (s > p.x)) t = 0;
bool new_tab = false;
if(t != lv_tabview_get_tab_act(tv)) new_tab = true;
lv_tabview_set_act(tv, t, LV_ANIM_ON);
}
}
Reference source: https://forums.100ask.net/t/topic/336
Effect
100ask
4
v9 version:
static void scroll_begin_event(lv_event_t * e)
{
lv_obj_t * cont = lv_event_get_target(e);
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * tv = lv_obj_get_parent(cont);
if(lv_event_get_code(e) == LV_EVENT_SCROLL_END) {
lv_indev_t * indev = lv_indev_active();
if(indev && lv_indev_get_state(indev) == LV_INDEV_STATE_PRESSED) {
return;
}
int32_t tb_index;
lv_coord_t s;
lv_point_t p;
lv_obj_get_scroll_end(cont, &p);
if(lv_obj_get_style_flex_flow(lv_tabview_get_tab_bar(tv), 0) != LV_FLEX_FLOW_COLUMN) {
s = lv_obj_get_scroll_x(cont);
if(s < 0) tb_index = lv_tabview_get_tab_count(tv) - 1;
if((tb_index == (lv_tabview_get_tab_count(tv) - 1)) && (s > p.x)) tb_index = 0;
}
else {
s = lv_obj_get_scroll_y(cont);
if(s < 0) tb_index = lv_tabview_get_tab_count(tv) - 1;
if((tb_index == (lv_tabview_get_tab_count(tv) - 1)) && (s > p.y)) tb_index = 0;
}
bool new_tab = false;
if(tb_index != (int32_t)lv_tabview_get_tab_active(tv)) new_tab = true;
/*If not scrolled by an indev set the tab immediately*/
if(lv_indev_active()) {
lv_tabview_set_active(tv, tb_index, LV_ANIM_ON);
}
else {
lv_tabview_set_active(tv, tb_index, LV_ANIM_OFF);
}
if(new_tab) lv_obj_send_event(tv, LV_EVENT_VALUE_CHANGED, NULL);
}
}
lv_obj_add_event_cb(lv_tabview_get_content(tabview), scroll_begin_event, LV_EVENT_SCROLL_END, NULL);