gpt4 book ai didi

ios - TItanium Studio - iOS - 带标签子的 ListView

转载 作者:行者123 更新时间:2023-11-29 10:42:27 24 4
gpt4 key购买 nike

我的问题如下:我有一个 ListView ,我需要在其中动态加载一组标签(我不知道其长度), ListView 的每个子项(即每个标签)的高度应该改变根据标签的长度,可惜我不知道该怎么做

enter image description here

测试 - 代码

var win = Titanium.UI.createWindow();

var template = {
childTemplates : [{
type : 'Ti.UI.Label',
bindId : 'label',
properties : {
left : 0,
width : 300,
height : 'auto',
textAlign : "left",
color : "red",
font : {
fontSize : 12
},
backgroundColor : "#42de0b"
}

}]
};


var tabella = Ti.UI.createListView({
width : 300,
height : 300,
separatorColor : 'transparent',
backgroundColor : 'transparent',
separatorInsets : {
left : 0,
right : 0
},
showVerticalScrollIndicator : false,
templates : {
'plain' : template
},
defaultItemTemplate : 'plain'
});


var data_record = [];

for (var i = 0; i < 10; i++) {

data_record.push({

label : {
text : "test test test test test test test test test test test test test test test test test "
},
properties : {
selectionStyle : Ti.UI.iPhone.ListViewCellSelectionStyle.NONE,
height : 20
}
});

}


var intestazione = Ti.UI.createListSection();
tabella.sections = [intestazione];


intestazione.appendItems(data_record, {
animationStyle : Ti.UI.iPhone.RowAnimationStyle.TOP
});

win.add(tabella);

win.open();

最佳答案

设置ListView模板的高度为Ti.UI.SIZE而不是 'auto'

var template = {
childTemplates : [{
type : 'Ti.UI.Label',
bindId : 'label',
properties : {
left : 0,
width : 300,
height : Ti.UI.SIZE,
textAlign : "left",
color : "red",
font : {
fontSize : 12
},
backgroundColor : "#42de0b"
}

}]
};

关于ios - TItanium Studio - iOS - 带标签子的 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23876184/

24 4 0