2.SuperScrollView:无限滚动解决方案
- 什么是无限滚动?
无限滚动是指滚动列表中的Item对象,支持无限回收在利用的循环滚动列表。 - 作用
利用对象回收利用的机制,提升在进行大批量数据滚动显示时的性能。
SetListItemCount: 重新设置滚动列表个数。
数据增减必须调用此接口,否则会出现 item 索引与数据不一致和其他显示 Bug。

RefreshAllShownItem: 更新所有可见的 item 最新数据
![]()
MovePanelToItemIndex: 直接瞬移到目标索引 Item 处

SetSnapTargetItemIndex: 以缓动动画的形式平滑滚动到目标索引 Item 处

using SuperScrollView;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RankWindow : MonoBehaviour
{
public LoopListView2 loopListView;
private List<RankData> mRankList;
private void Awake()
{
RefreshListView();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
RankDataManager.Instance.AddRankData(50);
RefreshListView();
}
if (Input.GetKeyDown(KeyCode.W))
{
RankDataManager.Instance.AddRankData(50);
RefreshListView(false);
}
if (Input.GetKeyDown(KeyCode.R))
{
MoveItemToIndex(50);
}
if (Input.GetKeyDown(KeyCode.T))
{
MoveItemToIndexScroll(50);
}
}
public void RefreshListView(bool resPos = true)
{
mRankList = RankDataManager.Instance.RankDataList;
if (!loopListView.ListViewInited)
{
loopListView.InitListView(mRankList.Count, OnGetItemByIndex);
}
else
{
loopListView.SetListItemCount(mRankList.Count, resPos);
loopListView.RefreshAllShownItem();
}
}
public void MoveItemToIndex(int index)
{
loopListView.MovePanelToItemIndex(index, 0);
loopListView.RefreshAllShownItem();
}
public void MoveItemToIndexScroll(int index)
{
loopListView.SetSnapTargetItemIndex(50, 30000);
loopListView.RefreshAllShownItem();
loopListView.mOnSnapItemFinished = (listView, item) =>
{
loopListView.RefreshAllShownItem();
};
}
LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index)
{
if (index < 0 || index >= mRankList.Count)
return null;
RankData rankData = mRankList[index];
if (rankData == null)
return null;
LoopListViewItem2 item = listView.NewListViewItem("RankItem");
RankItem itemScript = item.GetComponent<RankItem>();
if (!item.IsInitHandlerCalled)
{
item.IsInitHandlerCalled = true;
itemScript.Init();
}
itemScript.SetItemData(rankData, index);
return item;
}
}
