选项卡布局

重要

本文介绍的功能和指南为公共预览版,在正式发布之前可能会有重大修改。 Microsoft 不对此处提供的信息作任何明示或默示的担保。

TabLayout 是一种自定义的 TabLayout。 当应用程序跨具有垂直折叠功能的设备上的显示屏显示时,可以使用 displayPosition 参数使小组件在折叠功能左侧、右侧或上方呈现。

displayPosition

返回或设置指定视图将在哪个屏幕上呈现的值。 可以是以下三个值之一:

  • DisplayPosition.START
  • DisplayPosition.END
  • DisplayPosition.DUAL

下面将详细解释这些值。

DisplayPosition.START

选项卡分组到第一个屏幕上。 START: tabs on the first screen

DisplayPosition.END

选项卡分组到第二个屏幕上。 END: tabs on the first screen

DisplayPosition.DUAL

选项卡跨两个屏幕显示。 选项卡可能出现在折叠功能下方,这通常是不希望出现的行为。 使用 arrangeButtons 避免出现这种情况。 DUAL: tabs on both

tabLayout.displayPosition = DisplayPosition.START

可以使用 app:display_position 属性来实现同样的效果:

<com.microsoft.device.dualscreen.tabs.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tool:tools_application_mode="dual_screen"
    ...
    app:display_position="start"
     />

arrangeButtons

当应用程序跨折叠功能显示并且组件具有奇数个按钮时,中间的按钮可能会被铰链或折叠挡住。 避免这种情况的一种方法是,在折叠功能的每一侧以不同的方式排列按钮:

The buttons can be arranged in different ways on the two screens

可通过 arrangeButtons 函数实现此效果。

tabLayout.arrangeButtons(2, 4)

useTransparentBackground

当应用程序跨屏幕显示,而一个屏幕上没有按钮时,可将该屏幕的背景变为透明:

DUAL: tabs on the second screen

tabLayout.useTransparentBackground = true

allowFlingGesture

如果设置为 true,可在组件上使用快速滑动手势将 displayPosition 设置为 DisplayPosition.STARTDisplayPosition.END

tabLayout.allowFlingGesture = true

可使用 `app:allowFlingGesture` 属性来实现同样的效果:

<com.microsoft.device.dualscreen.tabs.TabLayout
   app:allowFlingGesture="true"/>