8

我有兩個選項卡的活動。每個選項卡都包含一個片段,其中包含SwipeRefreshLayoutRecyclerView隱藏工具欄與CoordinatorLayout,但RecyclerView上的一個分段

在活動,我有一個AppBarLayout(具有ToolbarTabLayout)一個CoordinatorLayout和用於片段一個ViewPager。現在

Screenshot

,我要實現的是:當用戶滾動的片段,工具欄,而不是標籤,皮革,像在Play商店。

在我通過Internet讀取的示例中,佈局非常簡單:在同一個xml中,它們的RecyclerViewToolbar位於CoordinatorLayout之內。

然後,他們只寫:

<android.support.v7.widget.RecyclerView 
    android:id="@+id/rvToDoList" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

而且

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true"> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_scrollFlags="scroll|enterAlways"/> 
</android.support.design.widget.AppBarLayout> 

所以,我無法弄清楚如何做到這一點。

我的XML的有以下幾種:

的活動佈局是:

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

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="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:fitsSystemWindows="true"> 

      <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/activity_main_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="@color/color_primary" 
       app:layout_scrollFlags="scroll|enterAlways"/> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/activity_main_tab_layout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:tabIndicatorColor="@color/color_text_primary" 
       app:tabMode="fixed" /> 

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

     <android.support.v4.view.ViewPager 
      android:id="@+id/activity_main_tabs_pager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 


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

<ListView 
    android:id="@+id/activity_main_nav_drawer_list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:background="@color/color_primary" 
    android:choiceMode="singleChoice" 
    android:divider="@android:color/transparent" 
    android:dividerHeight="5dp" 
    android:overScrollMode="never" 
    android:smoothScrollbar="true" /> 
</android.support.v4.widget.DrawerLayout> 

而且片段:提前

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/fragment_coupons_swipe_refresh_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<com.github.yasevich.endlessrecyclerview.EndlessRecyclerView 
    android:id="@+id/fragment_coupons_recycler_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scrollbars="vertical" /> 
</android.support.v4.widget.SwipeRefreshLayout> 

感謝。

+0

刪除'LinearLayout's – tachyonflux

+0

和'應用:layout_behavior = 「@字符串/ appbar_scrolling_view_behavior」'的'ViewPager',而不是'SwipeRefreshLayout' – tachyonflux

+0

都能跟得上,沒有對評論工作:(謝謝。 –

回答

3

男人,我面臨同樣的問題。問題不在代碼中。我敢打賭你正在使用構建工具和庫的舊版本。他們更新到最新:

  • buildToolsVersion 「22.0.1」
  • com.android.support:appcompat-v7:22.1.1
  • com.android.support:recyclerview-v7:22.2.0

在我的情況下,這個工作就像一個魅力!祝你好運!

+0

@LucasDaddiego,你是否設法嘗試我的解決方案?如果它對你有幫助,可否請你接受我的回答是正確的:) –

+0

嘿,早上好。是的,那是問題所在!謝謝! –

+0

很高興知道它有幫助:) –

2

對於使用在片段的滾動視圖大家和我一樣,我建議你使用android.support.v4.widget.NestedScrollView。這樣一來,工具欄和/或TabLayout將與滾動型一起滾動

相關問題