Hi, I’m testing listview and adding Text and buttons. So far so good. However the list is always filled from top to bottom and I would like to add items on the Bottom side instead of Top side. I have been checking the API and testing a few options but I couldn’t manage to do it. Any feedback would be very much appreciated!
Thanks!
Add them from top index to bottom, I mean if your listView size is 5, then start adding the text and buttons at index 4 then 3,2,1,0. thats it. So that it looks like 0( at top),1,2,3,4 (at bottom).
Hi, I didnt know I can reserve the size of the listview. How can i do that? I’ve been checking the API and havent found a way to do it.
Now I just create the listivew and I add widgets to it.
///Add the below code in your required layer. and change the names and sprites according to your requirements
this.achieveScreeen = new ccui.ListView();
this.achieveScreeen.setDirection(ccui.ScrollView.DIR_VERTICAL);
this.achieveScreeen.setTouchEnabled(true);
this.achieveScreeen.setBounceEnabled(true);
this.achieveScreeen.setBackGroundColor(new cc.color(0, 0, 0));
this.achieveScreeen.setContentSize(cc.size(this.bgPanel._getWidth(),this.bgPanel._getHeight()*0.5));
this.achieveScreeen.setInnerContainerSize(cc.size(this.bgPanel._getWidth(),this.bgPanel._getHeight()));
this.achieveScreeen.setScrollBarEnabled(false);
this.achieveScreeen.setLayoutComponentEnabled(true);
this.achieveScreeen.setAnchorPoint(cc.p(1, -0.5));
this.bgPanel.addChild( this.achieveScreeen,1);
this.achieveScreeen.setClippingEnabled(true);
for(var i=4;i>=0;i–)
{
var achieve1=new achieveNode();
achieve1.setContentSize( this.achieveScreeen._getInnerWidth(), this.achieveScreeen._getInnerHeight()*0.2);
achieve1.setLayoutComponentEnabled(true);
//achieve1.setBackGroundImage(res.achievePanel);
achieve1.setPosition(0, achieve1._getHeight()*i);
achieve1.setMainLbl(mainLbl[i][langIndex]);
achieve1.setSubLbl(subLbl[i][langIndex]);
achieve1.display();
achieve1.setBright(false);
this.achieveScreeen.addChild(achieve1, 1);
}
//and add this object also
var achieveNode=ccui.Layout.extend({
mainLbl:null,subLbl:null,achieveSpr:null,isAchieved:false,maxwidth:0,//scaleLbl:null,
ctor:function()
{
this._super();
},
init:function()
{
this.mainLbl=new ccui.Text("main","res/fonts/SFSlapstickComic.ttf",30*lblScaleFactor);
this.mainLbl.setAnchorPoint(0, 1);
this.mainLbl.setColor(new cc.Color(136,000,021));
this.addChild(this.mainLbl, 0);
this.subLbl=new ccui.Text("sub","res/fonts/SFSlapstickComic.ttf",22*lblScaleFactor);
this.subLbl.setAnchorPoint(0, 0);
this.subLbl.setColor(new cc.Color(136,000,021));
this.addChild(this.subLbl, 1);
//this.scaleLbl=new ccui.Text("scale","gameFont",30*lblScaleFactor);
//this.scaleLbl.setAnchorPoint(0, 1);
//this.addChild(this.scaleLbl, 1);
this.achieveSpr=new ccui.ImageView(res.achieveIconSel);
this.achieveSpr.setScale(0.65, 0.65);
this.achieveSpr.setAnchorPoint(0.5,0.5);
this.addChild(this.achieveSpr, 1);
return true;
},
});
Hope this will Help you
I will try it! thanks!