Cluster
Request access介绍
本教程将指导您如何在车辆的仪表盘集群上集成导航元素。
Cluster 活动
Automotive Navigation Application 包含一个专用的 Cluster Activity,旨在在车辆的仪表盘集群上显示导航信息。
Cluster Activity 提供了一个可定制的 UI,用于显示导航元素,如地图、操作指令和预计到达时间(ETA)信息。
它会自动适应当前的导航状态,确保向驾驶员展示相关信息。

如何集成 Cluster Activity
定义默认配置
集成 Cluster Activity 的第一步是定义您自己的默认配置。
Cluster Activity 可以在启动时通过在启动 Activity 的 intent 中传递 JSON 配置作为额外参数来配置。
该配置允许您定义在 Cluster 上显示哪些组件及其布局。
请参阅下文的 配置参数 部分,了解可用配置参数及其默认值的概述。
启动 Cluster Activity
Cluster Activity 可以通过 intent 启动。
虽然可以使用内置的默认配置启动 Cluster Activity,但建议在启动时传递适当的默认配置作为额外参数。
val myClusterActivityDefaultConfiguration = """ { "displayHpComponent": true, "displayVignette": true, "displayPX": false, (...), }""".trimIndent()
val intent = Intent()intent.action = "com.tomtom.automotive.clusterui.cluster.COMPONENT_VISIBILITY"intent.addCategory("android.car.cluster.NAVIGATION")intent.putExtra("clusterConfigurationUpdate", myClusterActivityDefaultConfiguration)startActivity(intent)运行时更新配置
您可以通过启动 Cluster Activity 时使用的相同 intent 在运行时更新配置。
请注意,配置更新不需要详尽无遗,这意味着您可以只更新想要更改的参数。
更改 ETA 组件可见性的示例
您可以通过 intent 编程方式更新配置:
val intent = Intent()intent.action = "com.tomtom.automotive.clusterui.cluster.COMPONENT_VISIBILITY"intent.addCategory("android.car.cluster.NAVIGATION")intent.putExtra("clusterConfigurationUpdate", "{\"displayHpComponent\": false}")startActivity(intent)同样也可以通过 adb 实现:
adb shellam start -a "com.tomtom.automotive.clusterui.cluster.COMPONENT_VISIBILITY" \ -c "android.car.cluster.NAVIGATION" \ --es "clusterConfigurationUpdate" '{"displayHpComponent": false}'配置参数
Cluster Activity 的配置使用 JSON 定义,支持以下参数:
| 参数 | 描述 | 类型 | 默认值 |
|---|---|---|---|
displayHpComponent | 如果参数设置为 true,则在 Cluster 上显示 Horizon Panel 组件,否则隐藏。 | boolean | true |
hpComponentRect | 表示一个矩形,用于配置 Horizon Panel 的尺寸和位置。 ![]() | object | 实现定义 |
hpElementsToShowOnCluster | 配置在 Horizon Panel 上显示哪些子面板。
![]() | set | CMP |
nipLayoutType | 表示 Next Instruction Panel(作为 Horizon Panel 的一部分显示)的布局配置。 | string | NORMAL_LAYOUT |
etaLayoutType | 表示 ETA 面板的布局配置类型(作为 Horizon Panel 的一部分显示)。 | string | MINIMAL |
displayMapComponent | 如果参数设置为 true,则在 Cluster 上显示地图组件,否则隐藏。 | boolean | true |
displayVignette | 如果参数设置为 true,则在 Cluster 的外缘显示渐晕效果,否则隐藏。 | boolean | true |
displayPX | 如果参数设置为 true,则支持像素显示配置。 | boolean | false |
safeAreaComponentRect | 表示一个矩形,用于配置 Cluster 上安全区域组件的尺寸和位置。 | object | 实现定义 |
示例配置
下面是一个示例配置:
{ "displayHpComponent": true, "hpComponentRect": { "topMargin": 0, "startMargin": 0, "width": 403, "height": 640 }, "hpElementsToShowOnCluster": [ "CMP" ], "nipLayoutType": "NORMAL_LAYOUT", "etaLayoutType": "MINIMAL", "displayMapComponent": true, "displayVignette": true, "displayPX": false, "safeAreaComponentRect": { "topMargin": 0, "startMargin": 574, "width": 574, "height": 840 } }最佳实践
由于您只能配置(而不能修改)Cluster Activity:
- 适应您的显示密度:根据仪表盘集群的显示特性,适当使用
displayPX参数。

