我正在尝试绘制一个带有buttonText和右文本的按钮。 XML文件如下。
<?xml version="1.0" encoding="utf-8" ?>
<component name="settingsButtons" extends="Group">
<interface>
<field id="itemContent" type="node" onChange="itemContentChanged"/>
</interface>
<script type="text/brightscript" >
<![CDATA[
sub itemContentChanged()
itemData = m.top.itemContent
m.buttonRect.width = itemData.buttonWidth
m.buttonRect.height = itemData.buttonHeight
m.buttonRect.color = itemData.buttonColor
m.buttonText.text = itemData.titleText
m.buttonText.translation = m.defaultTextTranslation
m.buttonText.color = itemData.textColor
m.buttonRightText.text = itemData.rightText
m.buttonRightText.translation = m.defaultRightTextTranslation
m.buttonRightText.color = itemData.textColor
end sub
sub initCoordinates()
m.defaultTextTranslation = "[30, 20]"
m.defaultRightTextTranslation = "[790, 20]"
end sub
sub init()
initCoordinates()
m.buttonRect = m.top.findNode("buttonRect")
m.buttonText = m.top.findNode("buttonText")
m.buttonRightText = m.top.findNode("buttonRightText")
end sub
]]>
</script>
<children>
<Rectangle id="buttonRect" translation="[0, 0]" width="820" height="70">
<Label id="buttonText" height="29" horizAlign = "left" vertAlign = "center" translation="[0, 0]" >
<Font role="font" uri="pkg:/fonts/NHaasGroteskDSStd-75Bd.otf" size="24" />
</Label>
<Label id="buttonRightText" height="29" horizAlign = "right" vertAlign = "center" translation="[0, 0]" >
<Font role="font" uri="pkg:/fonts/NHaasGroteskTXStd-55Rg.otf" size="24" />
</Label>
</Rectangle>
</children>
</component>
即使我将horizAlign保持为右,从显示buttonText的位置(即,显示为左对齐)也将显示buttonRightText。您能告诉我如何解决此问题吗?
答案 0 :(得分:1)
在SDK doc中,需要指定宽度(不等于0)以使horizAlign起作用。
一种选择是使所有两个标签与矩形共享相同的宽度,并将平移保持为[0, 0]
。
sub itemContentChanged()
itemData = m.top.itemContent
m.buttonRect.width = itemData.buttonWidth
m.buttonRect.height = itemData.buttonHeight
m.buttonRect.color = itemData.buttonColor
m.buttonText.text = itemData.titleText
m.buttonText.width = itemData.buttonWidth
m.buttonText.color = itemData.textColor
m.buttonRightText.text = itemData.rightText
m.buttonRightText.width = itemData.buttonWidth
m.buttonRightText.color = itemData.textColor
end sub