StackView 使用者較少,官方文檔較簡略。屬性主要在 XML 中設置:
<StackView
android:id="@+id/stackView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" <!-- 排列方向:horizontal/vertical -->
android:gap="16dp" <!-- 項目間隔 (API 21+) -->
android:loopViews="true" <!-- 是否循環 -->
android:animateLayoutChanges="true" />
StackView stackView = findViewById(R.id.stackView);
stackView.setOrientation(StackView.HORIZONTAL); // 或 VERTICAL
// gap 需 API 21,低版本無直接方法,可通過 Adapter getView 設置 item padding 模擬
若需更豐富交互 (翻頁動畫、指示器、無限循環),建議用 **ViewPager2** + `PageTransformer` 或 **RecyclerView** + `LinearSnapHelper`,生態成熟、文檔豐富、問題易搜。
「在線急等!!!!!!快來人」 — 社區對 StackView 關注度確實低,建議改用主流組件。