我希望在一个tablerow中有一个带有一天名字的标签。这意味着我不知道标签的实际宽度,并且即使在postlayout事件之后,label.toImage()。width也不会返回实际大小。而且我想要将滚动视图与随机文本水平对齐,有时非常大。我拥有的是:
var storehoursscrollingmessagestyle = {
left:"10dp",
font:{fontSize:'18dp',fontWeight:"bold"}
};
var storehoursscrollviewstyle = {
contentWidth: 'auto',
contentHeight: 'auto',
height: '70dp',
width:Ti.UI.FILL,
scrollType: 'horizontal'
};
var storehoursrowstylegray={
classNane:"storeoptions",
selectedBackgroundColor:"#E8E8E8",
backgroundColor:"#E8E8E8",
height:"70dp"};
var storehoursrowlabelstyle={
left:"10dp",
height:"70dp",
font:{fontSize:'18dp',fontWeight:"bold"},
color:"Black"
};
var storehoursviewrowstyle ={
width:'200dp',
height:'70dp',
layout:'horizontal'
};
var storehoursbuttontitleview = Titanium.UI.createLabel(storehoursrowlabelstyle);
storehoursbuttontitleview.text = dayMappings[today] + " " + openTimeFormatted + " - " + closeTimeFormatted;
storehoursbuttonview.add(storehoursbuttontitleview);
var view = Ti.UI.createView(storehoursviewrowstyle);
var scrollview = Ti.UI.createScrollView(storehoursscrollviewstyle);
scrollview.add(storehoursscrollingmessagetitleview);
view.add(storehoursbuttontitleview);
var subviewviewforscrollview = Ti.UI.createView(storehoursviewrowstyle);
subviewviewforscrollview.add(scrollview);
view.add(subviewviewforscrollview);
storehoursbuttonview.add(view);
如果我将宽度:'30%'设置为storehoursscrollviewstyle,水平布局将显示为应该显示,但如果我设置为100%,滚动视图将消失。
所以我的问题是如何在表格行中放置标签和滚动视图,而不知道它们的大小,也没有为彼此设置硬编码的宽度值。
答案 0 :(得分:0)
我是通过将postlayout事件添加到我的标签来实现的,还从视图和硬编码宽度中删除了水平布局。
function storehoursbuttontitleview_postlayout(e) {
if (e.source.set == null) {
var storehoursscrollingmessagetitleview = Titanium.UI.createLabel(storehoursscrollingmessagestyle);
storehoursscrollingmessagetitleview.text = e.source.closedMessage;
var view = Ti.UI.createView(storehoursviewrowstyle);
view.left = e.source.size.width + 20 + "dp";
var scrollview = Ti.UI.createScrollView(storehoursscrollviewstyle);
view.add(scrollview);
if (Titanium.Platform.name != 'android') {
var str = e.source.closedMessage;
var chunks = [];
for (var i = 0, charsLength = str.length; i < charsLength; i += 100) {
chunks.push(str.substring(i, i + 100));
}
var finalwidth = 0;
for (i=0; i<chunks.length; i++) {
var storehoursscrollingmessagetitleviewtemp = Titanium.UI.createLabel(storehoursscrollingmessagestyle);
storehoursscrollingmessagetitleviewtemp.text = chunks[i];
finalwidth = finalwidth + storehoursscrollingmessagetitleviewtemp.toImage().width;
}
var labelInsideScrollWidth = finalwidth;
storehoursscrollingmessagetitleview.width = finalwidth + 10 + "dp";
scrollview.add(storehoursscrollingmessagetitleview);
}
else {
scrollview.add(storehoursscrollingmessagetitleview);
}
e.source.row.add(view);
e.source.set = true;
}
}