2017-04-22 51 views
1

我的代码如下所示:崩溃工具栏无法显示viewpager的标签下的布局内容

<?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。所以我怎样才能在tab布局下显示viewpager?

+0

移动你的tablayout代码appbar布局 –

+0

不,它确实没有工作。如果我将标签布局移动到appbar布局,它会粘在顶部,视差效果消失 –

+0

那么您需要准确吗? –

回答

0

移动工具栏下方的tablayout内折叠式工具