Ejemplo n.º 1
0
    /// <summary>
    /// 初始化界面与数据
    /// </summary>
    /// <typeparam name="TData"></typeparam>
    /// <param name="datas"></param>
    public override void InitData <TData>(IEnumerable <TData> datas)
    {
        if (scrollView != null)
        {
            if (itemPrefab != null)
            {
                scrollRect = scrollView.GetComponent <ScrollRect>();
                DemoManager.Instance.SendTerminalMessage("RecyclerViewType:" + recyclerViewType);
                switch (recyclerViewType)
                {
                case RecyclerViewType.Vertical:
                    scrollRect.horizontal = false;
                    scrollRect.vertical   = true;
                    VerticalLayoutSettings layoutSetting = new VerticalLayoutSettings();
                    list = new VerticalScrollList(scrollRect, itemPrefab, layoutSetting);
                    break;

                case RecyclerViewType.Horizontal:
                    scrollRect.horizontal = true;
                    scrollRect.vertical   = false;
                    HorizontalLayoutSettings horizontalSetting = new HorizontalLayoutSettings();
                    list = new HorizontalScrollList(scrollRect, itemPrefab, horizontalSetting);
                    break;

                case RecyclerViewType.Grid:
                    scrollRect.horizontal = true;
                    scrollRect.vertical   = true;
                    GridLayoutSettings layout = new GridLayoutSettings();
                    list = new GridScrollList(scrollRect, itemPrefab, layout);
                    break;
                }

                list.onRenderItem     += OnItemRender;
                list.onRebuildContent += OnRebuildContent;
                list.onRefresh        += OnListRefresh;
                SetData(datas);
                Debug.Log("recyclerViewType: " + recyclerViewType.ToString() + "datas.count:" + datas.Count());
            }
            else
            {
                Debug.LogError("请先设置 TamRecyclerView 的 itemPrefab !");
            }
        }
        else
        {
            Debug.LogError("请先设置 TamRecyclerView 的 ScrollView !");
        }
    }
Ejemplo n.º 2
0
    protected override void InitItems()
    {
        var datas = new int[itemCount];

        for (int i = 0; i < datas.Length; i++)
        {
            datas[i] = i;
        }

        var layout = new VerticalLayoutSettings();

        layout.gap        = 10;
        layout.paddingTop = 50;
        list = new VerticalScrollList(scrollView.GetComponent <ScrollRect>(), itemPrefab, layout);
        list.onRenderItem     += OnItemRender;
        list.onRebuildContent += OnRebuildContent;
        list.onRefresh        += OnListRefresh;
        list.AddRange(datas);
    }