如何创建一个顶部水平菜单?

huangapple go评论94阅读模式
英文:

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=&quot;horizontal&quot; to accomplish this. Here's a very rough example:

&lt;LayoutGroup id=&quot;navbar&quot; layoutDirection=&quot;horizontal&quot; vertAlignment=&quot;center&quot; itemSpacings=&quot;20&quot; translation=&quot;[500,34]&quot;&gt;
    &lt;Label text=&quot;Featured&quot; /&gt;
    &lt;Label text=&quot;Live TV&quot; /&gt;
    &lt;Label text=&quot;Shows&quot; /&gt;
&lt;/LayoutGroup&gt;

If you need to update these dynamically, you can do something like this:

sub init()
  &#39;get these from the server somehow, and then call this function
  navbarEntries = [&quot;Featured&quot;, &quot;Live TV&quot;, &quot;Shows&quot;];
  setNavbarItems(navbarEntries)
end sub

sub setNavbarItems(items)
  children = []
  for each item in items
    label = createObject(&quot;roSGNode&quot;, &quot;label&quot;)
    label.text = item
    children.push(label)
  end for
  navbar = m.top.findNode(&quot;navbar&quot;)
  &#39;remove all existing nodes
  navbar.removeChildrenIndex(navbar.getChildCount(), 0)
  &#39;add all the new navbar entries
  navbar.appendChildren(children)
end sub

如何创建一个顶部水平菜单?

huangapple
  • 本文由 发表于 2023年2月16日 13:51:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75468330.html
  • brightscript
  • heroku-api
  • roku
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定