cocos2dx ListView百分比计算

移动到当前窗口所需设置百分比=(列表总长度-列表视窗长度)/当前项距离顶端长度(当前项之前所有项长度之和+各项间距)

            if (_selectedItem)
            {
                // 当前项距离列表顶端长度(当前项之前所有项长度之和+间距)
                float selhight = 0.0f;
                for (auto item : _ui.ListView_Record->getItems())
                {
                    if (item == _selectedItem)
                    {
                        break;
                    }
                    selhight += item->getContentSize().height;
                    selhight += _ui.ListView_Record->getItemsMargin();
                }

                // 列表总长度-列表视窗长度
                float totalheight = _ui.ListView_Record->getInnerContainerSize().height - _ui.ListView_Record->getContentSize().height;
                
                float percent = 1;
                if (totalheight && selhight)
                    percent = 100.0f* selhight / totalheight;

                _ui.ListView_Record->jumpToPercentVertical(percent);

            }    

你可能感兴趣的:(cocos2dx ListView百分比计算)