2016-04-27 97 views
2

我遇到了一个问题,我无法修复它。 如果我没有设置图像,我希望我的折叠工具栏不能展开。 在我的片段中,当没有要设置的图像时,我将imageview可见性设置为GONE,但通过这样做,我的工具栏消失了(没有更多标题,没有更多菜单可访问)。 有人知道如何从展开禁用折叠工具栏吗?禁用collaspsingtoolbar扩展

我的XML

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

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

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

      <ImageView 
       android:id="@+id/image" 
       android:layout_width="match_parent" 
       android:layout_height="250dp" 
       android:scaleType="centerCrop" 
       android:src="@drawable/landscape" 
       android:fitsSystemWindows="true" 
       app:layout_collapseMode="parallax"/> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/toolbar_height" 
       android:layout_below="@+id/image" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:layout_collapseMode="pin" /> 


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

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabLayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom"/> 

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

     <android.support.v4.widget.NestedScrollView 
      android:id="@+id/scroll" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:clipToPadding="false" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
    <FrameLayout 
     android:id="@+id/main_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/tabLayout" /> 
     </android.support.v4.widget.NestedScrollView> 
    </android.support.design.widget.CoordinatorLayout> 

<android.support.design.widget.NavigationView 
    android:id="@+id/navigation_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/menu_recycler_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:layout_marginLeft="10dp"> 
    </android.support.v7.widget.RecyclerView> 

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

在我的第一个片段设置ImageView的知名度可见,并且在我的第二个片段我设置它的知名度了。

如果有人有这样的想法,这将是伟大的!

+0

你试过看不见? (而不是去)隐藏视图但保持是位置。 – MikeT

+0

那么,隐形的问题是,我collapsingtoolbar是可扩展的,我不希望它:( – Tibo

回答

0

在片段

mAppBarLayout.setExpanded(false, false);

mRecyclerView.setNestedScrollingEnabled(false);//你的情况NestedScrollView

工具栏永远不会展开。