英文:
how to create a top horizontal menu?
问题
我正在尝试创建一个顶部水平菜单。下面是一个示例。它可以只是突出显示的文本,具有特定的颜色,没有花哨的东西。Roku有垂直列表,但没有看到水平的。我应该如何实现这个,哪个模板最合适。谢谢!
此外,我想在从菜单内容导航时隐藏和显示该菜单(分层)。
英文:
I am trying to create a top horizontal menu. Example below. It could be just highlighted text with specific color, nothing fancy. Roku has verical lists but haven't seen any horizontal. How would I accomplish this, what template best fits. Thank You!
In addition, I would like to hide and show that menu (layered), when navigation from menu content.
答案1
得分: 2
你可以使用 layoutDirection="horizontal"
的 LayoutGroup 来实现这一点。这里是一个非常简单的示例:
<LayoutGroup id="navbar" layoutDirection="horizontal" vertAlignment="center" itemSpacings="20" translation="[500,34]">
<Label text="Featured" />
<Label text="Live TV" />
<Label text="Shows" />
</LayoutGroup>
如果需要动态更新这些内容,可以像这样进行操作:
sub init()
'从服务器获取这些数据,然后调用此函数
navbarEntries = ["Featured", "Live TV", "Shows"]
setNavbarItems(navbarEntries)
end sub
sub setNavbarItems(items)
children = []
for each item in items
label = createObject("roSGNode", "label")
label.text = item
children.push(label)
end for
navbar = m.top.findNode("navbar")
'移除所有现有节点
navbar.removeChildrenIndex(navbar.getChildCount(), 0)
'添加所有新的导航栏条目
navbar.appendChildren(children)
end sub
英文:
You can use a LayoutGroup with layoutDirection="horizontal"
to accomplish this. Here's a very rough example:
<LayoutGroup id="navbar" layoutDirection="horizontal" vertAlignment="center" itemSpacings="20" translation="[500,34]">
<Label text="Featured" />
<Label text="Live TV" />
<Label text="Shows" />
</LayoutGroup>
If you need to update these dynamically, you can do something like this:
sub init()
'get these from the server somehow, and then call this function
navbarEntries = ["Featured", "Live TV", "Shows"];
setNavbarItems(navbarEntries)
end sub
sub setNavbarItems(items)
children = []
for each item in items
label = createObject("roSGNode", "label")
label.text = item
children.push(label)
end for
navbar = m.top.findNode("navbar")
'remove all existing nodes
navbar.removeChildrenIndex(navbar.getChildCount(), 0)
'add all the new navbar entries
navbar.appendChildren(children)
end sub
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论