将 View inside ViewPager 放在 TabLayout 下面

Put View inside ViewPager below TabLayout

我正在寻找一种方法将 view 放在 ViewPagerTabBar 的下方。 我不希望它在每个 fragment 内,因为显然每次我更改当前片段时它都会滚动;我需要在没有动画的情况下将视图固定在那里。

这就是我现在将 View 放入我的 TabLayout [code + img]

    <android.support.v4.view.ViewPager
        android:id="@+id/mViewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.design.widget.TabLayout
            android:id="@+id/mTabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabBackground="@color/colorPrimary"
            app:tabGravity="fill"
            app:tabMode="fixed"
            app:tabSelectedTextColor="@color/colorAccent"
            app:tabTextColor="@color/white">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="end"
                android:background="@drawable/background_accent_fading"
                android:paddingBottom="5dp"
                android:paddingEnd="5dp"
                android:paddingTop="5dp"
                android:text="RIPASSO"
                android:textAlignment="textEnd"
                android:textColor="@color/white"
                android:textStyle="bold" />

        </android.support.design.widget.TabLayout>
    </android.support.v4.view.ViewPager>

这正是我要找的东西

如您所见,RIPASSO 在我的选项卡下方,但它固定在那里。

有获取途径吗?我什么都没找到

您的 TabLayout 不能是 ViewPager 的子项。

<LinearLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="?android:actionBarSize"
                style="@style/AppTabLayout"
                app:tabTextAppearance="@style/AppTabTextAppearance"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                app:tabMode="fixed"
                app:tabGravity="fill"/>
            <!--here put your view, the one you want to appear in all pages.-->
        </LinearLayout>
    </android.support.design.widget.AppBarLayout>
    <FrameLayout
        android:id="@+id/popup_holder"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:background="@android:color/white"/>
    </FrameLayout>
</LinearLayout>

您可以使用默认的 android 选项卡,请按照以下步骤操作: 右键单击应用 > 新建 > Activity > 选项卡式 Activity。 它会为你创造一切。 如果你想改变背景颜色的颜色 - 下划线颜色或文本颜色。 您可以在 XML 或用户

中完成
TabLayout tabLayout = binding.tabs;
    tabLayout.setupWithViewPager(mViewPager);
    tabLayout.setTabTextColors(getResources().getColor(R.color.white), getResources().getColor(R.color.white));