0

我有一个梦想......不,不是这样。我有一个视图,在我添加 createTableView 之前一切正常。当我这样做时,它会替换之前出现在屏幕上的所有内容。我如何同时拥有地图视图和表格视图?

var self = Ti.UI.createView();

var mapview = Titanium.Map.createView({
    top:1,
    height:200,
    mapType: Titanium.Map.STANDARD_TYPE,
    region:{latitude:33.74511, longitude:-84.38993, latitudeDelta:0.5, longitudeDelta:0.5},
    animate:true,
    regionFit:true,
    userLocation:true
});

self.add(mapview);

var lbl = Ti.UI.createLabel({
    text:'Please select an item',
    height:'auto',
    width:'auto',
    color:'#000'
});
self.add(lbl);

self.addEventListener('itemSelected', function(e) {
    lbl.text = e.name+': $'+e.price;
});

detailData = [{title:"Foo",leftImage:"bar.png",hasChild:true}];


var table = Ti.UI.createTableView({
    data:detailData
});
// if i dont rem the below line all i get on screen is the table view
self.add(table);
4

1 回答 1

1

TableView 控件通常会占据整个屏幕,我会尝试将 MapView 添加到 TableView 的其中一行,但是,这可能不适用于 Android

// Create the table
var self = Ti.UI.createView();
var detailData = [{title:"Foo",leftImage:"bar.png",hasChild:true}];
var table = Ti.UI.createTableView({
    data : detailData
});
self.add(table);

// Create the mapview
var mapview = Titanium.Map.createView({
    top:1,
    height:200,
    mapType: Titanium.Map.STANDARD_TYPE,
    region:{latitude:33.74511, longitude:-84.38993, latitudeDelta:0.5, longitudeDelta:0.5},
    animate:true,
    regionFit:true,
    userLocation:true
});

// Insert a row in first index of the table that has the mapview in it
var row = Ti.UI.createTableViewRow();
row.add(mapview);
table.insertRowBefore(1, row);

编辑:

糟糕,更简单的方法是设置表格的高度,并使您的容器视图具有垂直布局:

// Create the container view
var self = Ti.UI.createView({
    layout : 'vertical'
});
// Add the mapview
var mapview = Titanium.Map.createView({
    height:200,
});
self.add(mapview);
// Add the table
var table = Ti.UI.createTableView({
    top : 0,
    data : detailData
});
self.add(table);
于 2013-07-14T16:12:28.010 回答