总的来说,就是有一个容器container : 锚点(0,0),大小(为全部内容的大小), scrollView: 大小,锚点,代理(setDelegate),视窗大小(setViewSize),设置容器(setContainer), 方向;
CCNode* m_pMedalContainer;
CCScrollView* m_pScrollView;
m_pMedalContainer = CCNode::create();
m_pMedalContainer->retain();
m_pMedalContainer->setAnchorPoint(ccp(0, 0));
CCSize listSize = ccp(300, 200);
m_pScrollView = CCScrollView::create(listSize);
m_pScrollView->setAnchorPoint(CCPointZero);
m_pScrollView->setDelegate(this);
m_pScrollView->setViewSize(listSize);
m_pScrollView->setContainer(m_pMedalContainer);
m_pScrollView->setDirection(kCCScrollViewExDirectionHorizontal);
pMyLayer->addChild(m_pScrollView); //(pMyLayer为m_pScrollView的父容器,游戏里自己定义)
//添加内容
m_pMedalContainer->removeAllChildren();
m_pMedalContainer->setContentSize(CCSizeMake(1200, 200)); //容器的大小
MyItem* pItem; //MyItem为游戏里自定义的一个类
float xPos, yPos;
for (int i = 1; i < maxLevel; i++)
{
pItem = MyItem::create(i);
xPos = (i - 1) * 158 + 35;
yPos = 0;
pItem->setPosition(ccp(xPos, yPos));
m_pMedalContainer->addChild(pItem);
}