//-------∽-★-∽------∽-★-∽--------∽-★-∽ListViewScroll∽-★-∽--------∽-★-∽------∽-★-∽--------// void ShowListViewScroll() { m_listViewScroll = ComponentUtil.EnsureComponent <KListViewScroll>(m_scrollViewItemList.gameObject); m_listViewScroll.itemViewType = typeof(Item1); m_listViewScroll.onDataChanged.AddListener(UpdateListItem2); LayoutParam param = m_listViewScroll.layoutParam; //param.padding = new Padding(20, 20, 20, 20); param.itemGap = new Vector2(10, 50); param.divNum = 3; //param.dir = LayoutDirection.LeftToRight; List <int> datas = new List <int>(); int num = 999; for (int i = 0; i < num; ++i) { datas.Add(i); } //m_listViewScroll.direction = KScrollView.ScrollDir.horizontal; m_listViewScroll.ShowList(datas); }
//-------∽-★-∽------∽-★-∽--------∽-★-∽ListView∽-★-∽--------∽-★-∽------∽-★-∽--------// void ShowListView() { GameObject container = GameObjUtil.FindChild(m_scrollViewItemList.gameObject, "Image_mask/Container_content"); List <int> datas = new List <int>(); int num = 10; for (int i = 0; i < num; ++i) { datas.Add(i); } m_listView = ComponentUtil.EnsureComponent <KListView>(container); m_listView.itemViewType = typeof(Item1); m_listView.onDataChanged.AddListener(UpdateListItem); LayoutParam param = m_listView.layoutParam; //param.padding = new Padding(20, 20, 20, 20); param.itemGap = new Vector2(10, 50); //param.divNum = 2; m_listView.ShowList(datas); }
//-------∽-★-∽------∽-★-∽--------∽-★-∽Layout∽-★-∽--------∽-★-∽------∽-★-∽--------// void ShowLayout() { LayoutParam param = new LayoutParam { }; param.padding = new Padding(20, 20, 20, 20); param.itemGap = new Vector2(50, 50); param.divNum = 2; GameObject itemGo = GameObjUtil.FindChild(m_scrollViewItemList.gameObject, "Image_mask/Container_content/Container_Item"); GameObject container = GameObjUtil.GetParent(itemGo); itemGo.SetActive(false); for (var i = 0; i < 10; ++i) { GameObject item = GameObjUtil.Instantiate(itemGo); item.SetActive(true); GameObjUtil.ChangeParent(item, container); LayoutUtil.LayItem(param, i, item); m_idx2item[i] = item; } }
void initList(int[] array, bool isCreateTitle = false) { float H = padding.top; CountArray = array; for (int i = 0; i < CountArray.Length; i++) { if (isCreateTitle) { //创建title GameObject title; if (i >= _titleList.Count) { title = (GameObject)GameObject.Instantiate(titleTemp); title.transform.SetParent(content.transform); title.transform.localScale = new Vector3(1f, 1f, 1f); RectTransform rt = title.GetComponent <RectTransform>(); rt.anchorMin = new Vector3(0, 1); rt.anchorMax = new Vector3(0, 1); rt.pivot = new Vector3(0, 1); _titleList.Add(title); } else { title = _titleList[i]; } title.transform.localPosition = new Vector2(0, -H); title.SetActive(true); H += titleSize.height + spacing.y; if (onUpdateTitle != null) { //int realIndex = _titleList.IndexOf(title); onUpdateTitle(i, 0, 0, title); } } //创建layout参数 int line = Mathf.CeilToInt(CountArray[i] * 1f / lineCount); LayoutParam layout = new LayoutParam(); layout.posY = -H; layout.height = line * cellSize.height + (line - 1) * spacing.y; H += layout.height + spacing.y; _layoutMap.Add(i, layout); } content.GetComponent <RectTransform>().sizeDelta = new Vector2(viewSize.width, H + padding.bottom); checkLayout(); }
//-------~★~-------~★~-------~★~测试ListView~★~-------~★~-------~★~-------// void ShowListView() { LayoutParam layoutParam = m_listView.layoutParam; //layoutParam.dir = LayoutDirection.LeftToRight; //layoutParam.divNum = 2; layoutParam.origin = new Vector2(0, -200f); layoutParam.itemGap = new Vector2(0, 50f); //m_listView.direction = KScrollView.ScrollDir.horizontal; m_listView.onDataChanged.AddListener(UpdateListItem); //int len = MathUtil.RandomInt(10, 30); int len = 200; m_listView.ShowLen(len, 100); }
public void checkLayout() { Vector2 pos = content.transform.localPosition; foreach (var v in _layoutMap) { LayoutParam layout = v.Value; float h = layout.height; float posY1 = layout.posY + pos.y; float posY2 = layout.posY + pos.y - h; float start = 0f; float end = 0f; if (posY1 > 0 && posY2 <= 0 && posY2 >= -viewSize.height) //顶部超出 { start = posY1; end = h; } else if (posY1 <= 0 && posY1 > -viewSize.height && posY2 < -viewSize.height) //底部超出 { start = 0; end = viewSize.height + posY1; } else if (posY1 <= 0 && posY1 > -viewSize.height && posY2 < 0 && posY2 >= -viewSize.height) //完全包含 { start = 0; end = h; } else if (posY1 > 0 && posY2 < -viewSize.height) { start = posY1; end = posY1 + viewSize.height; } else { continue; } int _start = Mathf.FloorToInt(start / (cellSize.height + spacing.y)); int _end = Mathf.FloorToInt(end / (cellSize.height + spacing.y)); updateLayout(_start, _end, v.Key); } }