2015-12-21 60 views
0

所以,我一直在使用CoordinatorLayout顯示下方的工具欄和標籤這主要活動佈局:工具欄不會在列表中滾動隱藏

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

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

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      android:elevation="0dp" 
      local:layout_scrollFlags="scroll|enterAlways" 
      local:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/colorPrimary" 
      android:elevation="4dp" 
      local:tabMode="fixed" 
      local:tabGravity="fill"/> 

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:foreground="@drawable/header_shadow" 
     local:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

然後,我有2點片段佈局,每次各2我將擁有的標籤。一個片段顯示其內容的ListView

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:foreground="@drawable/header_shadow" 
    tools:context=".StationsFragment"> 

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipe_refresh_layout" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"> 

     <ListView 
      android:id="@+id/stations_listview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

    </android.support.v4.widget.SwipeRefreshLayout> 

</FrameLayout> 

我想我的工具欄隱藏,當我滾動上面列表視圖,它應該是確定與我的代碼,至少從我在這個answer閱讀,但它不起作用。目前我試圖從片段活動中刪除FrameLayout,但這並沒有解決問題。我認爲從列表視圖硬編碼滾動事件,但如果可能,我真的希望這是沒有代碼背後的工作..

在此先感謝。

+0

姆與layout_scrollFlags =「滾動| enterAlwaysCollapsed」嘗試在你的XML – Coeus

+0

@Coeus沒有工作:/,尋找答案 – yat0

回答

1

這是因爲你使用CoordinatorLayoutListView。您可以將您的實施更改爲RecyclerView以實現正確的滾動。

查看我的回答here。這可能會幫助你。

+0

所以這是不可能實現這與'ListView'除非硬編碼滾動事件,對吧?我使用的是ListView,因爲我從來沒有使用'RecyclerView',但似乎我必須使用它.. – yat0

+0

這是真的。我們必須轉到'RecyclerView'以利用與'toolbar'一起提供的功能。這種滾動效果只適用於'NestedScrollingChild'的孩子 – sha

+0

好吧,我明白了,謝謝你的回答 – yat0

0

嘗試改變從

local:layout_scrollFlags="scroll|enterAlways" 

local:layout_scrollFlags="scroll|exitUntilCollapsed" 
+0

由於沒有工作:/,感謝您的回答 – yat0

+0

嘗試添加嵌套滾動到你的片段。檢查我的編輯 –

+0

當你完成後讓我知道。 –