【问题标题】:Tablayout for Appbarlayout [duplicate]Appbarlayout 的 Tablayout [重复]
【发布时间】:2021-02-01 15:17:01
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            app:tabMode="scrollable">

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab1" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab2" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab3" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab4" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab5" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab6" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab7" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab8" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab9" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab10" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab11" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab12" />
        </com.google.android.material.tabs.TabLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".TabActivity" />
    </androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

我之前在answer 中注意到TabHost 没有被弃用的那个副本中问过TabHost 的问题。 TabLayout 已弃用。如果我使用TabLayout会更好吗?如果不是我应该使用的TabLayout 的替代品是什么?这是TabLayout。在this question AskNilesh 中说使用com.google.android.material.tabs.TabLayout。但是,我们将它用于TabLayout。我试图创建选项卡式活动

它还包含TabLayout

【问题讨论】:

    标签: java android android-tablayout


    【解决方案1】:

    使用TabLayout 会更好,因为TabHost is in fact deprecated(而TabLayout 不是)。查看文档,而不是 SO 问题...

    此类在 API 级别 30 中已弃用。 新的应用程序应该使用片段 API 而不是这个类:使用 TabLayout 和 ViewPager 来代替。

    【讨论】:

    • 但是,我的问题是如何滚动?在TabWidget 中我无法设置scrollable/tabMode。我想要tab 喜欢玩商店
    • 嗯,不,您的帖子中有两个问题:Would it be better if I use TabLayout? If not than what I should use what is the alternative of TabLayout? 而不是一个 scollable
    • 那么,您对可滚动有什么建议?
    • 我不知道,我不太熟悉TabHost/TabLayout的可编辑功能,对不起...
    猜你喜欢
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多