如何在android中实现垂直选项卡布局?

问题描述 投票:0回答:2

我正在尝试在平板电脑上运行的应用程序上实现垂直选项卡布局。我尝试将 TabLayout 的方向设置为垂直,但没有成功。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">



    <com.google.android.material.tabs.TabLayout
        android:id="@+id/staff_menu_tabs"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:orientation="vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.tabs.TabItem
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="Tab 1"/>
        <com.google.android.material.tabs.TabItem
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="Tab 2"/>
        <com.google.android.material.tabs.TabItem
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="Tab 3"
           />

    </com.google.android.material.tabs.TabLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

android android-layout kotlin material-design
2个回答
0
投票

我使用以下代码制作了垂直 tabLayout。

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:rotation="-90"
    android:transformPivotX="0dp"
    android:layout_marginTop="@dimen/tab_width"
    android:layout_marginLeft="-24dp">
    <com.google.android.material.tabs.TabLayout
        android:layout_width="@dimen/tab_width"
        android:layout_height="wrap_content"
        android:background="@color/black"
        app:tabTextColor="@color/light_grey"
        app:tabSelectedTextColor="@color/white"
        app:tabIndicatorHeight="2dp"
        app:tabIndicatorColor="@color/white"
        app:tabPaddingBottom="-10dp">
        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ABC"/>
        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="XYZ"/>
    </com.google.android.material.tabs.TabLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

0
投票

这是使用 Jetpack Compose 实现的 Vertical-TabLayout 库

https://github.com/mohdDanishCode/MDVerticalTabLayout

© www.soinside.com 2019 - 2024. All rights reserved.