-2

テーブルローに日の名前のラベルを付けたいです。これは、ラベルの実際の幅がわからないことを意味し、その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%に設定すると、スクロールビューが消えます。

したがって、私の質問は、サイズを知らずに、また相互にハードコードされた幅の値を設定せずに、テーブル行内にラベルとスクロールビューを配置する方法です。

4

1 に答える 1

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;
}
}
于 2013-03-19T10:45:49.263 に答える