【问题标题】:Titanium Appcelerator Dynamic TextArea height increaseTitanium Appcelerator 动态 TextArea 高度增加
【发布时间】:2012-06-09 05:00:30
【问题描述】:

我正在使用 Titanium 并尝试在 tableview 行中嵌入 textarea。 textarea 需要随着用户在其中键入以及 tableview 行动态增加高度。我知道它应该需要一些计算,但是我不知道算法。有人可以提供一些指示吗?

非常感谢。

到目前为止的代码:

var win = Ti.UI.createWindow({
    title: 'My Message'
});

var tableview = Ti.UI.createTableView({
    height: 'auto',
    layout: 'vertical',
    style:Titanium.UI.iPhone.TableViewStyle.GROUPED,
    headerTitle:'Message',
});

var tf = Ti.UI.createTextField({
    width: 200,
    top: 10,
    borderStyle: Ti.UI.INPUT_BORDERSTYLE_ROUNDED
});

var rowTo = Ti.UI.createTableViewRow({
    height: 'auto'
});


var ta = Ti.UI.createTextArea({
    height: 'auto',
    font: [{fontSize: 11}],
    top: 0,
    bottom: 20,
    width: 250,
    height: 50,
    backgroundColor: 'green'
});
var rowMsg = Ti.UI.createTableViewRow({
    height: 'auto'
});

rowTo.add(tf);
rowMsg.add(ta);

tableview.appendRow(rowTo);
tableview.appendRow(rowMsg);

win.add(tableview);
win.open();

【问题讨论】:

    标签: javascript iphone titanium titanium-mobile


    【解决方案1】:

    使用标签并将其高度分配给 textArea。在 textArea 的“更改”事件监听器中,更新 textArea 相对于标签高度的高度。请参阅下面的代码,我已更改它。

        var win = Ti.UI.createWindow({
        title : 'My Message'
    });
    
    var tableview = Ti.UI.createTableView({
        height : 'auto',
        layout : 'vertical',
        style : Titanium.UI.iPhone.TableViewStyle.GROUPED,
        headerTitle : 'Message',
    });
    
    var tf = Ti.UI.createTextField({
        width : 200,
        top : 10,
        borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED
    });
    
    var rowTo = Ti.UI.createTableViewRow({
        height : 'auto'
    });
    
    var ta = Ti.UI.createTextArea({
        font : [{
            fontSize : 11
        }],
        top : 0,
        width : 250,
        scrollable : false,
        backgroundColor : 'green',
        height : 'auto'
    });
    
    var label = Ti.UI.createLabel({
        width : 250,
        font : [{
            fontSize : 11
        }],
        height : 'auto',
        text : ta.value,
        visible : false
    });
    
    var rowMsg = Ti.UI.createTableViewRow({
        height : 'auto'
    });
    
    ta.addEventListener('change', function(e) {
        label.text = e.value;
        ta.height = label.height;
        rowMsg.height = label.height;
    });
    
    rowMsg.add(label);
    rowTo.add(tf);
    rowMsg.add(ta);
    
    tableview.appendRow(rowTo);
    tableview.appendRow(rowMsg);
    
    win.add(tableview);
    
    win.open();
    

    【讨论】:

      猜你喜欢
      • 2012-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多