主要思想:
源代码中 listview第一个cell排版位置默认偏移为0
所以只需在排版时给第一个cell一个偏移posSet值即可
在uilistview.h中添加
void setPosSet(float posSet);
float getPosSet();
float _posSet;
<span style="font-family: Arial, Helvetica, sans-serif;"> </span>
然后在uiListView中修改
函数实现
void ListView::setPosSet(float posSet){
if (_posSet == posSet) {
return;
}
_posSet = posSet;
_refreshViewDirty = true;
}
float ListView::getPosSet(){
return _posSet;
}
修改初始值
ListView::ListView():
_model(nullptr),
_gravity(Gravity::CENTER_VERTICAL),
_itemsMargin(0.0f),
_curSelectedIndex(0),
_refreshViewDirty(true),
_listViewEventListener(nullptr),
_listViewEventSelector(nullptr),
<strong><span style="color:#ff6666;">_posSet(0.0f),</span></strong>
设置内容的大小
void ListView::updateInnerContainerSize()
{
switch (_direction)
{
case Direction::VERTICAL:
{
size_t length = _items.size();
<strong>float totalHeight = (length - 1) * _itemsMargin+<span style="color:#ff6666;">2*_posSet</span></strong>;
for (auto& item : _items)
{
totalHeight