索引標籤版面配置

重要

本文說明 公開預覽 版的功能和指引,在正式推出之前可能會大幅修改。 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.START ,或在 DisplayPosition.END 元件上使用飛出手勢。

tabLayout.allowFlingGesture = true

您可以使用 屬性來取得相同的結果:

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