Skip to content

qtx TV 装饰预设 ​

生成 TV 页面时,给 qtx-list 写 decoration="tv",列表内部就套用内容边界与卡间距 / 行间距,list 尺寸不变、可全屏,业务不用再写 margin。页面级尺寸、间距、比例、颜色与字号全部从包级主题 QTX_TV 取,不要在每页重复声明常量;动作按钮收在右上角、不占独立工具条行。机器可读数值在站点静态资源 /design/qtx-layout-tokens.json(可直接下载),平台层规范见 Android TV / Google TV 基线。

1. 最简页面(可直接复制) ​

vue
<template>
  <div class="lt-page" :width="QTX_TV.screen.width" :height="QTX_TV.screen.height">
    <!-- 顶部栏:品牌 + 频道栏居中 + 右上角动作组,不占独立工具条行 -->
    <div class="lt-top" :width="QTX_TV.screen.width" :height="QTX_TV.navHeight">
      <qt-text text="QTX TV" :width="QTX_TV.brand.width" :height="QTX_TV.brand.height" class="lt-brand" />
      <div class="lt-top-gap-left" :width="gaps.left" :height="QTX_TV.navBarHeight" />
      <qtx-channel-nav
        :width="QTX_TV.channelNav.width" :height="QTX_TV.navBarHeight" :items="channels"
        :active="current" :focusedKey="focusedKey" linkId="home"
        initialActiveKey="history" initialFocusKey="history"
        @change="onChannelChange" />
      <div class="lt-top-gap-right" :width="gaps.right" :height="QTX_TV.navBarHeight" />
      <div class="lt-actions" :width="gaps.groupWidth" :height="QTX_TV.navBarHeight">
        <qtx-button text="搜索" :width="QTX_TV.action.width" :height="QTX_TV.action.height" :focusable="true" @click="onSearch" />
        <div class="lt-act-gap" :width="QTX_TV.action.gap" :height="QTX_TV.action.height" />
        <qtx-button text="筛选" :width="QTX_TV.action.width" :height="QTX_TV.action.height" :focusable="true" @click="onFilter" />
      </div>
    </div>

    <qtx-tabs :width="QTX_TV.screen.width" :height="QTX_TV.contentHeight" :active="current"
      linkId="home" :offscreen="2" :maxInstances="4">
      <qtx-tab-content tabKey="history" :width="QTX_TV.screen.width" :height="QTX_TV.contentHeight">
        <qtx-list decoration="tv" class="lt-feed" poolKey="home"
          :items="rows" :columns="QTX_TV.grid.columns" :width="QTX_TV.screen.width" :height="QTX_TV.contentHeight"
          key-field="id" @item-click="onItemClick">
          <template #item>
            <div :width="260" :height="160">
              <qt-text text="内置样式行" :width="260" :height="160" />
            </div>
          </template>
        </qtx-list>
      </qtx-tab-content>
    </qtx-tabs>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { QTX_TV, qtxTvTopGaps, styledRows } from '@quicktvui/qtx';

// 尺寸全部取自包级主题 QTX_TV(@quicktvui/qtx),页面不再自抄常量表。
// 本页只有一个页面级选择:右上角 2 个动作按钮;gap 由主题按按钮数反推。
const gaps = qtxTvTopGaps(2);

const channels = [{ key: 'history', label: '历史' }, { key: 'local', label: '本地' }];
const current = ref('history');
const focusedKey = ref('history');

// 内置样式行:span 占几列、aspectRatio 是宽 / 高,同一版块比例保持一致
const rows = styledRows([
  { id: 'h1', type: 'header', title: '最近打开', span: 6 },
  { id: 'p1', type: 'poster', title: '卡片 1', span: 2, aspectRatio: 0.667 },
  { id: 'p2', type: 'poster', title: '卡片 2', span: 2, aspectRatio: 0.667 },
  { id: 'p3', type: 'poster', title: '卡片 3', span: 2, aspectRatio: 0.667 },
]);

function onChannelChange(key: string) { current.value = key; }
function onItemClick() {}
function onSearch() {}
function onFilter() {}
</script>

<style>
/* 不用 scoped:qtx-list 是原生节点、#item 插槽转出的模板节点也不带 data-v,
   scoped 选择器匹配不到,列表会露出异色底色。类名带 lt- 前缀,避免与宿主工程
   非 scoped 的 .feed / .page 一类全局样式冲突。 */
/* 颜色是 QTX_TV.color 的运行时镜像:编译期样式解析器不支持 CSS 变量/JS 表达式,
   只能写字面量;取值必须等于 QTX_TV.color,换主题色时同步这些字面量。 */
/* 页面容器显式清零 padding:宿主默认内边距会把 1920 宽内容整体推偏、边界不再对称 */
.lt-page { width: 1920px; height: 1080px; background-color: #0B1016; flex-direction: column; padding-left: 0px; padding-right: 0px; padding-top: 0px; padding-bottom: 0px; }
.lt-top { width: 1920px; height: 128px; flex-direction: row; align-items: center; padding-left: 116px; padding-right: 116px; padding-top: 56px; }
.lt-brand { width: 240px; height: 64px; font-size: 40px; color: #FFFFFF; }
.lt-top-gap-left { width: 244px; height: 72px; }
.lt-top-gap-right { width: 258px; height: 72px; }
.lt-actions { width: 226px; height: 72px; flex-direction: row; align-items: center; }
.lt-act-gap { width: 10px; height: 44px; }
/* 列表底色与页面同色,保持深色统一;非 active Tab 的显隐由 qtx-tabs 处理 */
.lt-feed { width: 1920px; background-color: #0B1016; }
</style>

decoration="tv" 让 qtx-list 内部套用 116 / 56px 内容边界与 16 / 32px 卡间距 / 行间距,列表仍可全屏、业务不写 margin。不写 decoration 的既有页面行为不变。右上角动作组与品牌、频道栏同一行,内容区从 QTX_TV.navHeight 直接开始;按钮文案统一两字,超过两字会被截断。

带完整动作组、多 Tab、加载 / 空 / 错误态、触底分页、嵌套一行与三段式返回的完整首页见 TV 首页,直接复制那一页即可得到同样的对齐与留白。

全局主题 QTX_TV(尺寸 / 间距 / 比例 / 颜色 / 字号的唯一事实源) ​

一个应用的这些值都是定值,不该每个页面抄一份 const。从包里导入,模板直接引用:

ts
import { QTX_TV, qtxTvTopGaps } from '@quicktvui/qtx';

QTX_TV.screen.width            // 1920
QTX_TV.inset.h                 // 116,与 decoration="tv" 同源
QTX_TV.navHeight               // 128
QTX_TV.contentHeight           // 952
QTX_TV.grid.columns            // 6
QTX_TV.color.pageBg            // '#0B1016'
分组字段与值
screenwidth: 1920、height: 1080
inseth: 116、v: 56(与 decorationPresets.tv 同源)
顶部节奏topSafeV: 56、navBarHeight: 72、navHeight: 128、contentHeight: 952、topInnerWidth: 1688
brandwidth: 240、height: 64
channelNavwidth: 720、itemWidth: 160、itemHeight: 72、itemGap: 12、fontSize: 28、borderRadius: 36、itemPadding: 16、iconMargin: 16
actionwidth: 108、height: 44、gap: 10、count: 4、groupWidth: 462、cornerRadius: 22、fontSize: 22
gridcolumns: 6、heroSpan: 3 / heroAspectRatio: 1.78、posterSpan: 2 / posterAspectRatio: 0.667、fullSpan: 6
railwidth: 1688、height: 360、labelHeight: 52、innerHeight: 288、cellWidth: 240、cellHeight: 272、imageHeight: 180、titleHeight: 48、gap: 8
colorpageBg: #0B1016、surface: #16202C、card: #1E293B、text: #FFFFFF、textMuted: #94A3B8
fontbrand: 40、section: 30、button: 22、card: 24、label: 26

QTX_TV.channelNav 是「品牌 + 频道栏 + 右上角动作组」同排时的紧凑顶栏预设,由页面显式传给组件,720 宽内要放下 3 个频道。组件不写尺寸 props 时另有更宽松的默认间距(itemWidth: 240 / gap: 24 / iconMargin: 16),见 qtx-channel-nav 默认间距;两者用途不同,不要互相替换。

navHeight / contentHeight / topInnerWidth / topLeftGap / topRightGap / action.groupWidth / action.cornerRadius 都由基础值在主题内部算出,改基础值自动重算,页面不要手写算术。右上角按钮数不是 4 时调 qtxTvTopGaps(2),它返回 { groupWidth, left, right },频道栏仍保持居中。

页面允许保留的只有两类「本页选择」:按钮数量、栅格列数。除此之外不要声明 SCREEN_W / INSET_H / BTN_W 一类页面常量。

颜色与字号的运行时镜像:编译期样式解析器不支持 CSS 变量,也不允许在 <style> 里写 JS 表达式,所以 <style> 中的 background-color / color / font-size 仍是字面量,取值必须等于 QTX_TV.color / QTX_TV.font;换主题色时同步这些字面量。#item 插槽会被转成原生模板,里面只能写字面量或 item.* 字段路径,不能写 QTX_TV.rail.* 一类的成员表达式。

机器可读全量数值:/design/qtx-layout-tokens.json 的 appTheme 段。

2. 数值表 ​

Google 官方公开值(960 × 540dp MDPI 基准,数值权威是 android-tv-tokens.json):

项目值
过扫描最小安全线左右 48dp / 上下 27dp
推荐内容布局边距左右 58dp / 上下 28dp
12 栏栅格单栏 52dp、栏间距 20dp、两侧 58dp、行间垂直间距 4dp
卡片比例16:9 / 1:1 / 2:3
同屏 1–5 张卡宽844 / 412 / 268 / 196 / 124dp,peaking 20dp
列表内容 padding / 行距 / 卡间距48dp / 32dp / 16dp / 8dp(官方 Compose for TV 教学示例)

decoration 预设取值(decoration="tv",1920 × 1080 实现口径;不是 Google 官方规范):

键值含义
insetH116px内容左右边界(由官方 58dp × 2)
insetV56px内容上下边界(由官方 28dp × 2)
gutter16px卡间距(官方行内卡片间距 8dp × 2)
rowGap32px行间距(官方行距 16dp × 2)
focusScale1.1焦点放大倍率

页面级尺寸(顶部安全区来自官方,其余为 qtx 建议;全部写进页面常量表而不是魔法数字):

项目值用途
顶部安全区56px官方 recommendedLayoutMargin.verticalDp = 28 × 2;且高于过扫描线 overscanMargin.verticalDp = 27 × 2 = 54px。交互元素不得越过这条线
导航行高度72px品牌 + 频道栏 + 右上角动作组同一行,从 y=56 开始
顶部栏总高128pxQTX_TV.topSafeV + QTX_TV.navBarHeight,不要靠垂直居中把元素推到距顶 30px
右上角按钮108 × 44px、间隔 10px胶囊动作按钮,不占独立工具条行;文案统一两字
频道栏容器 720px、单项 160 × 72px、间隔 12px由左右 gap 常量反推居中位置,不用手调
内容区高度952px1080 - 128,列表占满;导航隐藏后可直接全屏
导航↔第一行内容56px由 decoration="tv" 的 insetV 承担,不再另写 margin-top;与顶部安全区 56 对称

全局主题字段与完整首页示例见上一节的 QTX_TV 表与 TV 首页。需要把工具条放进 qtx-tab-content 随 Tab 缓存时,才另用 QTX_TV_PAGE_RHYTHM.toolbarHeightPx 与 navToContentGapPx,见 tab-toolbar 示例。

顶部 56 / 导航 72 / 导航↔内容 56 的垂直节奏来自官方安全区与推荐布局边距;Google 官方未公开 Tabs / Lists / Navigation drawer 的逐条定量间距,上表标为「qtx 建议」的项不得当作官方规范引用。

样式必须避开全局污染:qtx-list 是原生节点、#item 插槽转出的编译期模板节点不带 data-v,作用在它们上的样式要写在非 scoped 的 <style> 块里 —— scoped 匹配不到会让列表露出异色底色、内层列表高度变 0。类名要带页面专属前缀(如 tvh-):宿主工程常有非 scoped 的 .feed { margin-top: 72px } 一类全局样式,用通用类名会被命中,在导航和内容之间凭空多出一段空白。

3. 约束 ​

  1. 不要给 qtx-list 写 margin,也不要给 qtx-tab-content 写 padding / margin —— 根节点不生效,边界必须内聚在 list 内部。
  2. decoration="tv" 不改 columns:列数与 span 仍由业务数据决定。
  3. 不写 decoration 的既有页面行为不变。
  4. 页面根容器显式清零 padding:保证 116px 左右边界对称。非 active Tab 由 qtx-tabs 收敛为 INVISIBLE,列表底色只是视觉统一、不承担遮挡;完整写法见TV 首页。

4. 业务仍需写什么 ​

要写的说明
items / styledRows() 数据行数据形状见内置 item 参考
columns一行几列(如 6);decoration 不代填
aspectRatio / span卡片比例与跨列,同一版块比例一致

列数与 12 栏栅格不是同一单位:栅格是页面级内容边界与对齐,列表的 columns 是行内 span 的分母。

5. 自检清单 ​

  • [ ] qtx-list 写了 decoration="tv",没有为内容边界或间距手写 margin / 魔法数字
  • [ ] 没有给 qtx-list 或 qtx-tab-content 写 padding / margin
  • [ ] decoration="tv" 没有改 columns,每行 span 在 [1, columns] 内
  • [ ] 交互元素落在过扫描安全区内;内容边界按 116 / 56px
  • [ ] 同一版块卡片比例一致
  • [ ] 焦点放大不越界、不裁切
  • [ ] 不写 decoration 的既有页面行为未变化

API 事实由源码自动生成 · 请勿手工编辑