2016-07-22 57 views
0

我有一个活动包含2个片段作为制表符布局当我触摸第一个片段(选项卡)它需要滚动其工作正常,但当我触摸第二个片段(选项卡)我不要崩溃的工具栏布局只有两个片段的标签,我想在这片以帮助我,如果你知道this.XML含隐藏父级活动collapsingToolbar布局从子片段

enter code here 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 


    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapse_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 


     <ImageView 
      android:id="@+id/header" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#424242" 
      android:fitsSystemWindows="true" 
      android:scaleType="centerCrop" 

      app:layout_collapseMode="parallax" /> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="top" 

app:layout_collapseMode="pin" 
      /> 


     <Relative-layout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      "> 

      <Text-view 
      /> 

     <Text-view 

       /> 

      <View 
       android:id="@+id/view" 
       android:layout_width="wrap_content" 
       android:layout_height="2dp" 
       /> 

      <Image View 

      /> 

     </RelativeLayout> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs 
      android:layout_gravity="bottom" 
      /> 

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

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


<android.support.v4.view.ViewPager 

    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

<android.support.design.widget.FloatingActionButton 

    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    /> 

回答

0

设置一个TabSelected侦听器,并在选择第二个选项卡时,通过appBarLayout.SetExpanded(false, true);折叠工具栏,并将其高度设置得较小。
参见herehere