【问题标题】:display content in tableview having exactly two columns in Titanium在 tableview 中显示内容,在 Titanium 中恰好有两列
【发布时间】:2015-05-04 11:19:37
【问题描述】:

我有一个 json 响应,其中包含我想在 tableview 中显示图像的图像和其他内容,但它应该只包含两列且行数不受限制。

谁能帮忙解答这个问题?

代码:

for (var i = 0; i < jsonResponse.length; i++) 
{ 
    var row = Ti.UI.createTableViewRow({ 
        width : Ti.UI.SIZE, 
        height : Ti.UI.SIZE, 
        layout: "horizontal" 
    });

    var myImage = Ti.UI.createImageView({ 
        width : Ti.UI.SIZE, 
        height : Ti.UI.SIZE, 
        image : jsonResponse[i].cover_image_url 
    }); 

    row.add(myImage); 
    data.push(row); 
} 
table.setData(data); 
win2.add(tableview);

【问题讨论】:

  • 发布您尝试过的代码
  • ` for (var i = 0; i
  • 嗨@buntyrohra,尝试使用合金而不是经典。另外请将代码添加到问题中
  • @RenePot 能给个示例代码吗?
  • link 该链接是我想要的正确参考。有人可以帮忙吗?谢谢

标签: android titanium titanium-mobile


【解决方案1】:

应该这样做:

var rowHeight = 50; // just pick the right height here
var imageRowIsFull = false;
var row = Ti.UI.createTableViewRow({ 
        width : '100%', 
        height : rowHeight, 
        layout: "horizontal" 
    });
for (var i = 0; i < jsonResponse.length; i++) 
{ 
    var myImage = Ti.UI.createImageView({ 
        width : '50%', 
        height : rowHeight, 
        image : jsonResponse[i].cover_image_url 
    }); 

    myImage.addEventListener('click', function(event){
          //event handling here
    });

    row.add(myImage); 
    imageRowIsFull = false;

    if ( (i + 1) % 2 == 0) { //this will add a new row every 2 items.
       imageRowIsFull = true; 
       data.push(row); 
       row = Ti.UI.createTableViewRow({ 
            width : '100%', 
            height : rowHeight, 
            layout: "horizontal" 
       });
    }
} 

if (!imageRowIsFull) { //do not forget to add the last row
       data.push(row); 
}
table.setData(data); 
win2.add(tableview);

【讨论】:

  • 嘿,它正在工作。感谢您的代码。但是根据上面评论中提供的图像,对齐看起来并不好。你能帮我按照提供的链接进行布局吗? link
  • 我不明白你需要什么
  • 我只是希望您的代码像链接中提供的图像一样排列...图像视图的对齐方式不正确。如果您根据链接中的图像提供对齐,那就太好了。 link
  • 对不起,伙计。我不会为你编写代码 :) 布局并不难理解。一旦进入您的脑海,您就可以使用 Titanium 布局任何东西
  • 没关系.. 感谢您的代码。如果可能的话,请您帮我告诉如何获取每个图像的点击事件,因为在这种情况下,我将获得行事件。那会很好。感谢您的帮助。
猜你喜欢
  • 2015-01-07
  • 2014-10-16
  • 2018-04-10
  • 1970-01-01
  • 2020-05-08
  • 2020-12-03
  • 1970-01-01
  • 1970-01-01
  • 2012-05-30
相关资源
最近更新 更多