【问题标题】:Roku: How do I open a LabelList on a new screen?Roku:如何在新屏幕上打开 LabelList?
【发布时间】:2017-08-31 20:24:26
【问题描述】:

BrightScript,如何在新屏幕(不是主屏幕/场景)上打开以下 LabelList?

<?xml version = "1.0" encoding = "utf-8" ?>

<!--********** Copyright 2016 Roku Corp.  All Rights Reserved. **********-->

<component name = "LabelListExample" extends = "Group" initialFocus = "exampleLabelList" >

  <script type = "text/brightscript" >

    <![CDATA[

    sub init()
      m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"

      example = m.top.findNode("exampleLabelList")

      examplerect = example.boundingRect()
      centerx = (1280 - examplerect.width) / 2
      centery = (720 - examplerect.height) / 2
      example.translation = [ centerx, centery ]

      m.top.setFocus(true)
    end sub

    ]]>

  </script>

  <children >

    <LabelList id = "exampleLabelList" >

      <ContentNode role = "content" >
        <ContentNode title = "Renderable Nodes" />
        <ContentNode title = "Z-Order/Parent-Child" />
        <ContentNode title = "Animations" />
        <ContentNode title = "Events and Observers" />
        <ContentNode title = "On Demand Example" />
      </ContentNode>

    </LabelList>

  </children>

</component>

【问题讨论】:

    标签: xml roku brightscript


    【解决方案1】:

    我认为您需要更好地了解 SceneGraph API,以便了解如何执行此操作。 在您的 main.brs 文件中,使用 screen = CreateObject("roSGScreen") 创建 Roku 屏幕,使用该屏幕创建场景 scene = screen.CreateScene("Scene") 。 因此,您需要将所有自定义组件添加到该场景的 XML 文件中。 在您的组件文件夹中创建两个单独的文件 LabelListExample.brs 和 LabelListExample.xml。 在你的 LabelListExample.brs 添加这个

    sub init()
          m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"
    
          example = m.top.findNode("exampleLabelList")
    
          examplerect = example.boundingRect()
          centerx = (1280 - examplerect.width) / 2
          centery = (720 - examplerect.height) / 2
          example.translation = [ centerx, centery ]
    
          m.top.setFocus(true) 
    end sub
    

    在你的 LabelListExample.xml 添加这个:

        <?xml version="1.0" encoding="UTF-8"?>
        <component name = "LabelListExample" extends = "Group" initialFocus = "exampleLabelList" >
        <script type="text/brightscript" uri="pkg:/components/LabelListExample.brs" />
        <children >
    
            <LabelList id = "exampleLabelList" >
    
              <ContentNode role = "content" >
                <ContentNode title = "Renderable Nodes" />
                <ContentNode title = "Z-Order/Parent-Child" />
                <ContentNode title = "Animations" />
                <ContentNode title = "Events and Observers" />
                <ContentNode title = "On Demand Example" />
              </ContentNode>
    
            </LabelList>
    
          </children>
        </component>
    

    现在在您的 Scene.xml 文件中作为孩子,您应该添加以下内容:

    <Poster
         id="justPoster"
         translation="[0, 0]"
         width="1280"
         height="720" 
      />
    
    <Group id="customComponentView" visible="false">
        <exampleLabelList
           id="customComponent"
        />
    </Group>
    
    <Group id="defaultView" visible= "true">
      <Label id="justLabel"
            color="0xFFFFFF"
            translation="[50, 300]"
            wrap="true"
            width="1200"
            horizAlign="center"
            text="Hide me if you can"
            opacity="0.5"
            font = "font:MediumBoldSystemFont"
      />      
    </Group>
    

    所以最大的问题是:如何从仅包含标签的 defaultView 转到将具有此标签列表的 customComponentView?真的很简单,您只需要隐藏一个并显示另一个。您需要做的是在 Scene.brs 文件中添加 onKeyEvent() 函数(如果您从 .xml 执行所有操作,则在场景脚本中)。同样在 Scene init() 中,首先使用以下命令初始化您的视图和组件:

    m.defaultView = m.top.findNode(defaultView)
    m.customComponentView = m.top.findNode(customComponentView)
    m.labelList = m.top.findNode(customComponent)
    m.label = m.top.findNode(justLabel)
    

    在 onKeyEvent() 函数中,当按下遥控器上的“确定”按钮时,您可以控制哪个视图可见:

    m.defaultView.visible = false
    m.customComponentView = true
    

    当 customComponentView 变得可见时,您还需要设置焦点:

    m.labelList.setFocus(true)
    

    希望您能从这里继续。另请查看 Roku 文档以了解有关 onKeyEvent() 函数的更多信息。

    【讨论】:

    • 感谢您的回答,对我帮助很大!
    • 我很高兴能帮上忙。 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-25
    • 2012-09-27
    • 2022-07-09
    • 2011-11-26
    相关资源
    最近更新 更多