【发布时间】:2017-06-14 09:56:24
【问题描述】:
我最近将我的 appcelerator 项目从 5.5.1 Titan SDK 升级到了 6.1.0。
Android 上列表视图的自定义模板在 6.1.1 中的行为与它们在 5.5.1 和我使用的所有以前版本的钛中的行为不同。问题是在垂直布局视图中嵌套水平布局视图。
在此错误示例中,列表视图以英文显示水果名称,然后在英文名称下方水平显示法语、德语和西班牙语翻译。
从所附图片中可以看出,iPhone 版本正确显示,但 Android 版本缺少翻译。 Titanium 5.5.1 及更早版本在两个平台上都能正确显示。
在自定义模板中,我使用了背景颜色,以便于查看每个视图和标签的显示位置。
有谁知道为什么安卓版没有字幕?这是 Titanium 错误还是我做错了什么?
这里是重现 Android 错误所需的所有代码。确保您使用 Titanium 6.1.0 SDK
var win = Ti.UI.createWindow({backgroundColor: 'white'});
// Create a custom template that displays the English title, then three
// subtitles for French, German & Spanish laid out horizontally below the
// English title
var myTemplate = {
properties: {
height: Ti.UI.SIZE,
width: Ti.UI.FILL
},
childTemplates: [
{
type: 'Ti.UI.View',
properties: {
backgroundColor: '#fcf',
height: Ti.UI.SIZE,
layout: 'vertical',
left: 15,
right: 15,
width: Ti.UI.FILL
},
childTemplates: [
{ // English
type: 'Ti.UI.Label', // Use a label for the text
bindId: 'english', // Maps to the english property of the item data
properties: { // Sets the label properties
color: 'black',
font: { fontFamily:'Arial', fontSize: '20dp', fontWeight:'bold' },
left: 0
}
},
{ // Container for language subtitles
type: 'Ti.UI.View',
properties: {
backgroundColor: '#ffc',
height: Ti.UI.SIZE,
layout: 'horizontal', // subtitles should be laid out horiznontally
},
childTemplates: [
{ // French
type: 'Ti.UI.Label', // Use a label for the text
bindId: 'french', // Maps to the french property of the item data
properties: { // Sets the label properties
backgroundColor: 'gray',
color: 'white',
font: { fontFamily:'Arial', fontSize: '14dp' },
right: 10
}
},
{ // German
type: 'Ti.UI.Label', // Use a label for the text
bindId: 'german', // Maps to the german property of the item data
properties: { // Sets the label properties
backgroundColor: 'red',
color: 'white',
font: { fontFamily:'Arial', fontSize: '14dp' },
right: 10
}
},
{ // Spanish
type: 'Ti.UI.Label', // Use a label for the text
bindId: 'spanish', // Maps to the spanish property of the item data
properties: { // Sets the label properties
backgroundColor: 'blue',
color: 'white',
font: { fontFamily:'Arial', fontSize: '14dp' },
right: 10
}
}
]
}
]
}
]
};
// Create the list view
var listView = Ti.UI.createListView({
templates: { 'template': myTemplate },
defaultItemTemplate: 'template',
top: Ti.Platform.osname === 'iphone' ? 20 : 0 // Allow for iOS status bar
});
// Create the list data set
var fruitSection = Ti.UI.createListSection({ headerTitle: 'Fruits'});
var fruitDataSet = [
{ english: {text: 'Apple'}, french: {text: 'Pomme', visible: true}, german: {text: 'Apfel'}, spanish: {text: 'Manzana'}},
{ english: {text: 'Banana'}, french: {text: 'Banane'}, german: {text: 'Banane'}, spanish: {text: 'Plátano'}}
];
fruitSection.setItems(fruitDataSet);
// Add the data set to the list view
var sections = [fruitSection];
listView.setSections(sections);
// Add the list view to the main window and open it
win.add(listView);
win.open();
【问题讨论】:
-
尝试在listView.setSections(sections)之后设置fruitSection.setItems(fruitDataSet)。
标签: android ios iphone appcelerator appcelerator-titanium