有关使用brightscript的Scene Graph中ButtonGroup的问题

时间:2016-04-04 15:53:56

标签: brightscript

最近我正在构建一个包含一些按钮的频道,我正在尝试使用https://sdkdocs.roku.com/display/sdkdoc/ButtonGroup。 因为我试图将按钮分成两行,所以我在两行中尝试了两个buttongroup。像:

  

button1 button2

     

button3 button4 button5

这是我在xml中的原始代码:

<ButtonGroup layoutDirection =  "horiz" addItemSpacingAfterChild = "false" horizAlignment = "left">
    <Button
        id = "button1"
        text = "button1"/>
    <Button
        id = "Button2"
        text = "Button2"/>
</ButtonGroup>
<ButtonGroup layoutDirection =  "horiz" >
    <Button
        id = "Button3"
        text = "Button3"/>
    <Button
        id = "Button4"
        text = "Button4"/>
    <Button
        id = "Button5"
        text = "Button5"/>                          
</ButtonGroup>

如何删除每个buttongroup的自动对焦,因为我不想同时在button1和button3处自动对焦。

这是我的工作环境:

Roku2,Roku3,为Eclipse开发人员使用Eclipse Mars 2.0。

以下是我的一些问题:

因为ButtonGroup是从LayoutGroup扩展的。我发现只有LayoutGroup的属性可以工作,比如layoutDirection和addItemSpacingAfterChild。但是ButtonGroup中的属性不起作用。就像我试图改变文本的颜色一样,我试图改变最大宽度。它们都不起作用。 如何删除自动对焦并正确使用buttongroup?

有人可以帮忙解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

You should set buttons as an array of strings into "buttons" field of ButtonGroup. Here is what you need:

<ButtonGroup
    id="buttonGroup1"
    layoutDirection="horiz"
    addItemSpacingAfterChild="false"
    horizAlignment="left"
    focusFootprintBitmapUri="pkg:/"
    buttons="[&quot;button1&quot;, &quot;button2&quot;]"/>
<ButtonGroup
    id="buttonGroup2"
    layoutDirection="horiz"
    translation="[0, 100]"
    focusFootprintBitmapUri="pkg:/"
    buttons="[&quot;button3&quot;, &quot;button4&quot;, &quot;button5&quot;]"/>

Also, you can set buttons from BrightScript code:

buttonGroup1 = m.top.findNode("buttonGroup1")
buttonGroup1.buttons = ["button1", "button2"]

Thus, ButtonGroup will automatically create and append Button nodes to itself, which you can later get via:

button = buttonGroup1.getChild(0)

Finally, to remove autofocus from unfocused buttons you can set into "focusFootprintBitmapUri" field invalid string. This is kind of a hack, but it works and I couldn't find a better way.

buttonGroup.focusFootprintBitmapUri = ""