折叠工具栏无法在标签布局下显示viewpager的内容

时间:2017-04-22 06:20:15

标签: android

我的代码如下所示:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:title="Test">

            <ImageView
                android:id="@+id/toolbarImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/truck_test"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.design.widget.TabLayout
                android:id="@+id/tabsMain"
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:layout_below="@+id/toolbar"
                android:background="@android:color/white"
                app:tabGravity="fill"
                app:tabIndicatorHeight="5dp"
                app:tabMaxWidth="156dp"
                app:tabMinWidth="148dp"
                app:tabMode="fixed"
                app:tabSelectedTextColor="@color/colorRoyalPurple"
                app:tabTextColor="@color/colorGray89" />

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpagerMain"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/tabsMain"
                android:background="@color/colorMercuryE1"
                android:clipToPadding="false"
                android:paddingTop="10dp" />

            <LinearLayout
                android:id="@+id/showCart"
                android:layout_width="match_parent"
                android:layout_height="53dp"
                android:layout_alignParentBottom="true"
                android:background="@color/colorRoyalPurple"
                android:orientation="horizontal"
                android:visibility="invisible">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/itemCartText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="end"
                        android:layout_marginTop="10dp"
                        android:text="1"
                        android:textColor="@android:color/white"
                        android:textSize="12sp" />


                    <TextView
                        android:id="@+id/viewCart"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="end"
                        android:text="View Cart"
                        android:textColor="@android:color/white"
                        android:textSize="15sp" />

                </LinearLayout>

                <ImageView
                    android:layout_width="15dp"
                    android:layout_height="15dp"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="10dp"
                    android:background="@drawable/icon_arrow" />
            </LinearLayout>

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

现在,我在这里可以成功加载选项卡,但不知何故内部片段内的内容不会被加载。It hows like this。那么如何在标签布局下面显示viewpager?

1 个答案:

答案 0 :(得分:0)

将您的tablayout移动到折叠工具栏中的工具栏下方