2017-08-14 89 views
1

BrightScript,我该如何在新屏幕上打开以下LabelList(而不是的主屏幕/场景)?Roku:我如何在新屏幕上打开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> 

回答

3

我想你需要了解一个更好的SceneGraph API,这样你才能理解如何做到这一点。 在您的main.brs文件中,使用screen = CreateObject("roSGScreen")创建Roku屏幕,从该屏幕创建scene = screen.CreateScene("Scene")。 因此,您所有的自定义组件都需要添加到该场景的XML文件中。 在您的组件文件夹中创建两个单独的文件LabelListExample.brs和LabelListExample.xml。在Scene.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> 

现在你应该补充一点:: 在你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添加此

<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()与第一初始化视图和组件:当“OK”时按下遥控器上的按钮

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()函数的更多信息。

+0

谢谢你的回答,它帮了我很多! – Winston

+0

我很高兴我能帮上忙。 :-) –