android 钛应用加速器中未显示 TableView

TableView not showing in android titanium appcelerator

TableView 在 iOS 模拟器中显示...但在 android 物理设备中不显示... 它们是 运行 相同的代码并且没有发生错误。

var row = Titanium.UI.createTableViewRow({
                width : Titanium.UI.FILL,
                height : "20%",
                left : 0,
                backgroundColor : "orange",
                separatorColor : "transparent",
                fav_id:id,
            });

        var lblTitle = Ti.UI.createLabel({
            top : "5%",
            left : "0%",
            height : Titanium.UI.SIZE,
            width : "90%",
            text : title,
            textAlign : Ti.UI.TEXT_ALIGNMENT_LEFT,
            color : "black",
            //backgroundColor : 'blue',
            maxLines: 2,
            touchEnabled : false
        });

        var lblDate = Ti.UI.createLabel({
            top : "50%",
            left : "0%",
            height : Titanium.UI.SIZE,
            width : "90%",
            text : date,
            textAlign : Ti.UI.TEXT_ALIGNMENT_LEFT,
            color : "black",
            //backgroundColor : 'blue',
            //maxLines:1,
            touchEnabled : false
        });

        var lblCategory = Ti.UI.createLabel({
            top : "50%",
            left : "60%",
            height : Titanium.UI.SIZE,
            width : "90%",
            text : category,
            textAlign : Ti.UI.TEXT_ALIGNMENT_LEFT,
            color : "black",
            touchEnabled : false
            //backgroundColor : 'white',
            //maxLines:1,
        });

        row.add(lblTitle);
        row.add(lblDate);
        row.add(lblCategory);
        dataTable.push(row);
$.tblFavourite.data = dataTable;

android os 怎么了?设计会影响 tableview 的输出吗?

正如 Suraj 已经指出的那样,在 Android 中不可能使用百分比作为行高。但是我在 the Appcelerator forums 中找到了一个解决方法:

你应该自己计算你的百分比。使用 Ti.Platform.displayCaps.platformWidthTi.Platform.displayCaps.platformHeight 进行计算。

10% 高度示例:

height : Math.floor(Ti.Platform.displayCaps.platformHeight / 10)

我认为百分比在 tableViewRow 的情况下不起作用。 尝试设置 row.height = "50dp"
希望对您有所帮助。