在tianium中显示单选按钮标签问题?
我从以下链接创建了一个单选按钮,https://github.com/yozef/TiRadioButtonGroup。我能够看到单选按钮,但相应的单选按钮标签未显示。我们如何显示单选按钮标签。在tianium中显示单选按钮标签问题?
我的代码:
查看:
<Alloy>
<Window class="container">
<View id="radiopicker" ></View>
</Window>
</Alloy>
风格:
".container": {
backgroundColor:"red",
layout: 'vertical'
}
"#radiopicker":
{
width: '90%',
top: '25dp'
}
控制器:
(function() {
var radioButton = require('/ui/tiRadioButton');
var radioGroup2 = radioButton.createGroup({
groupId:1,
width:20,
height:150,
layout:'vertical',
radioItemsValue:['One', 'Two', 'Three'],
radioItemsPadding:10,
radioItemsBackgroundSelectedImage:'/radioButtonActive.png',
radioItemsBackgroundImage:'/radioButton.png',
radioItemsWidth:33,
radioItemsHeight:34
});
var button = Ti.UI.createButton({
title:'Get value'
});
button.addEventListener('singletap', function(e) {
alert("Vertical radioGroup selectedIdx: " + radioGroup2.selectedValue);
});
$.radiopicker.add(radioGroup2);
$.radiopicker.add(button);
})();
$.index.open();
截图:
标签方案一,二,三没有显示。请帮我解决这个问题。我也需要显示标签。
我想你应该在radioButtons附近贴一些标签。看看我的修改后的代码。它没有测试,但应该做的伎俩。也许你必须稍微调整一下width/height/left等属性。
(function() {
var radioButton = require('/ui/tiRadioButton');
var radioGroup2 = radioButton.createGroup({
groupId:1,
width:20,
height:150,
layout:'vertical',
radioItemsValue:['One', 'Two', 'Three'],
radioItemsPadding:10,
radioItemsBackgroundSelectedImage:'/radioButtonActive.png',
radioItemsBackgroundImage:'/radioButton.png',
radioItemsWidth:33,
radioItemsHeight:34
});
//Create a view to hold your labels
var labelsView = Ti.UI.createView({
height:150,
left: "30" //Or whereever you want to place it
layout:'vertical'
});
//Create the labels
var label1 = Ti.UI.createLabel({
text: "One",
height: "34",
width: Titanium.UI.SIZE
});
var label2 = Ti.UI.createLabel({
text: "Two",
height: "34",
width: Titanium.UI.SIZE
});
var label3 = Ti.UI.createLabel({
text: "Three",
height: "34",
width: Titanium.UI.SIZE
});
//Attach the labels to your view and your view to your radioPicker view
labelsView.add(label1);
labelsView.add(label2);
labelsView.add(label3);
$.radiopicker.add(labelsView);
var button = Ti.UI.createButton({
title:'Get value'
});
button.addEventListener('singletap', function(e) {
alert("Vertical radioGroup selectedIdx: " + radioGroup2.selectedValue);
});
$.radiopicker.add(radioGroup2);
$.radiopicker.add(button);
})();
$.index.open();
它没有工作。是否有可能通过单选按钮传递标签,何扫描我们编辑以下脚本文件https://github.com/yozef/TiRadioButtonGroup/blob/master/Resources/app.js – Vinod 2014-10-31 16:14:08
我不认为这是可能的直接传递它们。 itemValues指的是您点击单选按钮时返回的值,它们不会显示。正如@turtle已经指出应该可以实现它,但我对模块编辑不够了解。顺便说一句,你是什么意思,它不工作?标签是否显示或发生了什么? – 2014-10-31 16:19:32
我知道我的代码不适合开箱即用。例如,您可以通过布局重新排列主视图。或者你可以给你的观点绝对值。一切皆有可能。我想你可以选择是否将模块的功能实现到模块中,或者如果你尝试操作你自己的布局。我肯定会推荐第二种方法,因为它更简单,并且当你有疑问时人们更可能帮助你,因为他们熟悉Titanium布局。 – 2014-10-31 17:09:56
我已经通过您的代码了,发现您的窗口背景颜色设置为“白色”或“#ffffff”,而tiRadioButton.js模块标签颜色也设置为“白色”或“#ffffff”。因此你无法看到标签。
您可以更改窗口backgroundColor或标签颜色。
对于变化windowBackground颜色:
在abc.tss文件
".container": {
backgroundColor:"red", // any color you want
layout: 'vertical'
}
如需改变标签颜色:
在tiRadioButton.js文件
var radioItemLabel = Ti.UI.createLabel({
width:Ti.UI.SIZE,
height:Ti.UI.SIZE,
text: arg.radioItemsValue[i],
font: {}, // Can add your own font styles
color:'#FFFFFF', //Label color
top:isVertical?null:5, // 5 padding between RadioBtn & Label
left:!isVertical?null:5, // 5 padding between RadioBtn & Label
id:i,
});
// **在色彩领域,您可以更改标签颜色**
您必须从模块派发事件,例如tiRadioButton.js(添加到第61行)。 'self.fireEvent('updatedResult',{index:i});'然后从父窗口监听该事件,让模块监听触发事件'radioGroup.addEventListener('updatedResult',function(e){Ti .API.info(e.index)});' – Yozef 2014-11-03 19:39:50
非常感谢。 – Vinod 2014-11-04 05:25:41
同样的代码也可以在windows phone上运行吗? – Vinod 2014-11-10 12:29:26