Appcelerator alloy自定义listview项目布局不工作?
我按照下面的示例创建了一个listview 视图xml如下所示:Appcelerator alloy自定义listview项目布局不工作?,listview,layout,appcelerator,titanium-alloy,listviewitem,Listview,Layout,Appcelerator,Titanium Alloy,Listviewitem,我按照下面的示例创建了一个listview 视图xml如下所示: <ListView id="elementsList" defaultItemTemplate="elementTemplate"> <Templates> <ItemTemplate name="elementTemplate"> <Label bindId="symbol" id="symbol" /> &
<ListView id="elementsList" defaultItemTemplate="elementTemplate">
<Templates>
<ItemTemplate name="elementTemplate">
<Label bindId="symbol" id="symbol" />
<View id="atomProperties">
<Label bindId="name" id="name" />
<View id="secondLine">
<Label class="line2 fieldLabel" text="Number: " />
<Label class="line2" bindId="number" id="number" />
<Label class="line2 fieldLabel" text="Atomic Mass: " />
<Label class="line2" bindId="mass" id="mass" />
</View>
</View>
<ImageView bindId="image" id="image" />
</ItemTemplate>
</Templates>
<ListSection>
<ListItem symbol:text="H" symbol:color="#090" name:text="Hydrogen" number:text="1" mass:text="1.00794"/>
<ListItem symbol:text="He" symbol:color="#090" name:text="Helium" number:text="2" mass:text="4.002602"/>
<ListItem symbol:text="Li" name:text="Lithium" number:text="3" mass:text="6.941"/>
</ListSection>
</ListView>
"#symbol": {
left: 15,
color: "black",
font: { fontSize: 34, fontWeight: 'bold' }
},
"#symbol[platform=android]": {
left: 0
}
"#atomProperties": {
top: 0, left: 80, right: 0, bottom: 0,
layout: "vertical"
},
"#atomProperties[platform=android]": {
left: 65
},
"#name": {
left: 0, top: 4,
color: "black",
textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT,
font: { fontSize: 16 }
},
"#secondLine": {
left: 0, right: 0,
layout: "horizontal"
},
".fieldLabel": {
color:"#999"
},
".line2": {
font: { fontSize: 10 }
},
"#number": {
width: 30,
color: 'red'
},
"#mass": {
color: "blue"
}
我需要添加一个右对齐的名称旁边的时间标签,我需要标签质量是右对齐以及。所以我在名字下面加了一个时间标签
<Label bindId="name" id="name" />
<Label bindId="time" id="time" />
时间标签正确对齐,但它将显示在名称标签下方。如何使其与名称相同
我想给质量贴上右对齐的标签,所以我把它改为
"#mass": {
color: "blue",
right: 0,
textAlign: Ti.UI.TEXT_ALIGNMENT_RIGHT
}
但它不会起作用,标签质量仍然是不合理的。我如何使它正确合理
基本上,我希望我的listview项目布局如下所示
nametime
SYMBOL
numbermass
命名时间
象征
数字量
我会使ItemTemplate具有水平布局。首先使用左间距标记符号标签(您可能还需要使用高度和垂直对齐来获得正确对齐)。第二个是垂直布局的视图,包括名称和编号;此处的左侧设置是与符号的边距。第三种是垂直布局的视图,包括时间和质量;此处的左侧设置是“名称/编号”视图的边距。您可能需要为数字和质量添加顶部间距,以获得所需的效果。伪ish代码如下:
<ItemTemplate layout="horizontal">
<Label text="Symbol" left="0"></Label>
<View left="10" layout="vertical">
<Label text="name">
<Label text="number">
</View>
<View left="10" layout="vertical">
<Label text="time">
<Label text="mass">
</View>
</ItemTemplate>
您好,我根据建议调整了您的代码,但它仍然不起作用,而且概念似乎不正确。请参阅下面从android模拟器捕获的图像!()您的图像显示它们仍然垂直堆叠。尝试在ItemTemplate中插入视图容器。例如,…尝试添加一个仍然相同的视图容器。我想知道listview本身是否在内部是垂直布局导致了这种行为?
<ItemTemplate layout="horizontal">
<Label text="Symbol" left="0"></Label>
<View left="10" layout="vertical">
<Label text="name">
<Label text="number">
</View>
<View left="10" layout="vertical">
<Label text="time">
<Label text="mass">
</View>
</ItemTemplate>