FairyGUI进阶-滑动列表 虚拟列表 循环列表

1.虚拟列表置顶子项居中(初始化)

int itemIndex = _list.ChildIndexToItemIndex(midIndex);

_selectid = itemIndex;

_list.ScrollToView(_selectid,false,true); 

_list.scrollPane.SetPosX(_list.scrollPane.posX - GRoot.inst.width/2.0f, false);

2.指定中间的子项高亮

_list.scrollPane.onScroll.Add(ListDragHundler);

ShopItemTools itemtools = _list.GetChildAt(midIndex) as ShopItemTools;
int up = midIndex + 1 > viewCount ? midIndex : midIndex + 1;
int down = midIndex - 1 < 0 ? 0 : midIndex - 1;
itemtools.Select();
(_list.GetChildAt(up) as ShopItemTools).UnSelect();
(_list.GetChildAt(down) as ShopItemTools).UnSelect();
list.RefreshVirtualList();
int itemIndex = _list.ChildIndexToItemIndex(midIndex);
_selectid = itemIndex;

3.虚拟列表初始化(循环列表)

_list = contentPane.GetChild("_list").asList;
_list.SetVirtualAndLoop();
_list.itemRenderer = UpdateList;
_list.numItems = _data.skinarray.Length;
_list.scrollPane.onScroll.Add(ListDragHundler);
viewCount = _list.numChildren;
midIndex = (int)(viewCount / 2.0);

4.刷新子项

private void UpdateList(int index, GObject item)
{
       ShopItemTools itemtools =  item as ShopItemTools;
       itemtools?.Init( _data.skinarray[index]);
}

5.图示

猜你喜欢

转载自blog.csdn.net/xiongwen_li/article/details/126865594