How to align ccui button On listview

how to align ccui button on listview. iam unable to set X Y position. Only possible to move button using anchorpoints. but it’s not aligning that i am wanted. plz help me to solve this.
my code

for(var i =0 ; i< 15;i++)
{
this.btnJoin = new ccui.Button();
this.btnJoin.setTouchEnabled(true);
this.btnJoin.setTitleText(“Join”);
this.btnJoin.setTitleFontName(“Arial”);
this.btnJoin.setTitleFontSize(14);
this.btnJoin.setScale(0.5,0.7);
this.btnJoin.setPosition(cc.p(500,255));
this.btnJoin.anchorX = 10;
this.btnJoin.anchorY = 0.5;
this.btnJoin.setTitleColor(cc.color(255,255,255,250))
this.btnJoin.loadTextures( res.button_png, res.buttonS_png);
this.listView.addChild(this.btnJoin,20);
}

This is just setting all of your buttons to the same position use the value your looping to change the position i.e (setPosition(500, i * 50));

1 Like

hii… thanks for ur reply… i done like this. but even x position is not moving like before… i tried ur code also. the problem occur only when try to use uibutton as a child of listview.

var y = 720;
for(var i =0 ; i< 15;i++)
{
this.btnJoin = new ccui.Button();
this.btnJoin.setTouchEnabled(true);
this.btnJoin.setTitleText(“Join”);
this.btnJoin.setTitleFontName(“Arial”);
this.btnJoin.setTitleFontSize(14);
this.btnJoin.setScale(0.5,0.7);
this.btnJoin.setPosition(400,y);
this.btnJoin.setTitleColor(cc.color(255,255,255,250))
this.btnJoin.loadTextures( res.button_png, res.buttonS_png);
this.listView.addChild(this.btnJoin,20);
y=y-40;
}

Even i have the same issue …need help!

same issue…can anyone help with this??

howw to solve this issuee…?? need help… advanced thanxxx :blush:

I have had the same problem but with aligning ccui.Text() components within the ccuui.ListView.
What worked for me is to add the ccui.Text components to a ccui.Layout widget. Then the x & y positioning works.

var name = new ccui.Text();
name.attr({
	textAlign: cc.TEXT_ALIGNMENT_LEFT,
	string: scoreItem.playerName,
	font: '28px Helvetica',
	x: 0,
	anchorX: 0,
	anchorY: 0
});
var score = new ccui.Text();
score.attr({
	textAlign: cc.TEXT_ALIGNMENT_LEFT,
	string: scoreItem.score,
	font: '28px Helvetica',
	x: 300,
	anchorX: 0,
	anchorY: 0
});

var layout = new ccui.Layout();
layout.setContentSize(XIYZ.WINDOW_SIZE.width / 2, 50);

layout.addChild(name);
layout.addChild(score);

listView.pushBackCustomItem(layout);