TabLayout上方的标题布局

6

我正在尝试做类似于这样的事情:

http://i.imgur.com/NwewaBx.png

我目前有上述布局,但还没有实现标题。我只需要弄清如何添加标题。

这是我想要放在选项卡上方的标题布局:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="center_horizontal"
        android:background="@color/green">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="wrap_content"
                android:layout_height="match_parent" >

                <ImageView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:background="@drawable/ic_image"
                    android:adjustViewBounds="true"
                    android:scaleType="centerCrop"
                    android:layout_gravity="center_vertical" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Hey!"
                    android:textColor="@color/white"
                    android:textSize="24sp"
                    android:layout_gravity="center_vertical" />

            </LinearLayout>

    </LinearLayout>

</LinearLayout>

我在选项卡下方使用了一个 RecyclerView。我为 Activity 使用了 3 个不同的 Fragments

这是我的 Activity:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar_group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="0dp"
            android:background="@color/blue"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabTextAppearance="@style/TabLayout"
            app:tabSelectedTextColor="@color/white"
            app:tabTextColor="@color/white"
            />

    </android.support.design.widget.AppBarLayout>

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

</android.support.design.widget.CoordinatorLayout>

这是我的一个片段之一:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</android.support.design.widget.CoordinatorLayout>

如何在TabLayout上方添加标题并保持正常滚动行为?


FrameLayout可能非常适合此用途,因为您可以将其放置在屏幕的任何位置。因此,实现此目标的一种可能的方法是--没有工具栏,使用Framelayout并在其中放置任何您想要的内容,包括其他布局,将其定位在所需位置,并在其下方放置选项卡。 - Tasos
只有您的建议中的内容部分是可滚动的。 :/ - user5314557
请检查此库 https://github.com/noties/Scrollable - orium
1个回答

0

请重新阅读我的问题并查看提供的图片。你提供的链接不是我要找的东西。 - user5314557

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接