17

我正在查看手機上的Twitter應用程序。Android:將TabLayout引腳滾動到頂部滾動查看

twitter app

你可以看到,當用戶滾動起來,則tabLayout實際上只是引腳本身到工具欄上的底部精美,不動的。

我想也許他們是通過將應用程序的所有頂部(配置文件圖片,自行車的輪廓壁紙,文本)放到CollapsingToolBarLayout和AppBarLayout中來實現的,但實際上只有輪廓壁紙與草地上的自行車是CollapsingToolBarLayout和AppBarLayout的一部分,因爲這是實際崩潰的唯一部分。文本部分只是向上滾動,tabLayout只是插在工具欄下方的頂部。

我在twitter應用程序上讀取積分,看起來他們使用SlidingTabLayout來實現其效果。 SlidingTabLayout類似於tabLayout,後者在支持庫中受支持。

它看起來像所使用的主流應用時下還有一個相當普遍的模式 -

Google+應用使用它在他們的個人資料視圖上的應用程序:

google+

的Facebook時刻在其應用中使用它:

facebook moments

任何想法他們怎麼做都設法做到這一點?

我正在尋找類似於所有這些應用的東西。

我的要求是:

  1. 有,當你向上滾動
  2. 有collapsingToolBarLayout下面一個TextView,將滾動和「隱藏」在工具欄的下面,當它完全崩潰坍塌一collapsingToolBarLayout。
  3. 在textview下面有一個tabLayout,當你滾動collapsingToolBarLayout下的textview時它將「粘」到tabLayout。
  4. 有tabLayout下方的recyclerview這樣,當您單擊tabLayout每個選項卡上,recyclerview將「推文」的列表之間進行切換,「照片」,「收藏」等

我看着二人發佈在SO上的其他問題:

Can the tab selection indicator of TabLayout be pinned to the top of the screen while scrolling?。這裏的答案似乎改變了tabLayout的行爲,但我懷疑改變行爲實際上會產生什麼twitter應用程序。正如我所提到的,tabLayout似乎位於CollapsingToolBarLayout和AppBarLayout之外,並且該行爲只有在位於CollapsingToolBarLayout和AppBarLayout內時纔有效。

How to pin TabLaout at top of ScrollView?。這個問題與我所問的內容類似,但沒有提供足夠的細節,也沒有答案。

回答

4

對於那些前3個問題,期待here

至於你需要爲每個標籤創建片段,而當選擇他們爲一個簡單的方法加載它們,也可以創建一個片段,並與它通信到第4當選擇一個標籤顯示的具體內容..

編輯 無法找到一個更新的鏈接所以這裏的答案

  1. 使用CoordinaterLay出。
  2. 任何想要用工具欄摺疊(或隱藏)的東西都會進入collapsingToolBarLayout。
  3. Collapsed工具欄在CollapsingToolbarLayout之後進入AppBarLayout的任何東西。

前 -

<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:background="@android:color/background_light" 
    android:fitsSystemWindows="true" 
    > 

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

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

      <ImageView 
       android:id="@+id/main.backdrop" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="centerCrop" 
       android:fitsSystemWindows="true" 
       android:src="@drawable/material_flat" 
       app:layout_collapseMode="parallax" 
       /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/main.toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:layout_collapseMode="pin" 
       /> 
     <!-- ADD ANY THING THAT GETS SCROLLED ALL THE WAY UP WITH TOOLBAR --> 
     </android.support.design.widget.CollapsingToolbarLayout> 

    <!--- ADD TAB_LAYOUT HERE---> 

    </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" 
     > 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:lineSpacingExtra="8dp" 
      android:text="@string/lorem" 
      android:padding="@dimen/activity_horizontal_margin" 
      /> 
    </android.support.v4.widget.NestedScrollView> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_margin="@dimen/activity_horizontal_margin" 
     android:src="@drawable/ic_comment_24dp" 
     app:layout_anchor="@id/main.appbar" 
     app:layout_anchorGravity="bottom|right|end" 
     /> 
</android.support.design.widget.CoordinatorLayout> 
+0

這很有趣,但我實際上昨晚觀看了精確的Slidenerds視頻,並認爲如果我創建兩個單獨的Collapsingtoolbarlayout,它實際上會工作。稍後再試。 – Simon

+0

它實際上並沒有完成我想做的事情。當我查看slidenerd示例時,該示例向上滑動,並且tabLayout和工具欄都從屏幕上消失。我可以通過將scollFlag更改爲exitUntilCollapsed來將其固定在頂部,但是textview和tabLayout都會粘到工具欄的頂部,這不是我想要的。我想要textview滾動屏幕和tabLayout來堅持。 – Simon

+0

你需要一個collasingBarLayout裏面,你將有2個孩子1.工具欄的屬性collapsMode =「pin」和,2. TextView的屬性collapseMode =「視差」 –

1

默認情況下,可能沒有支持該庫的庫。但你確實可以通過一點編程來實現它。通過ViewTreeObserver收聽scrollview事件,並操作其他事件。如果你還不確定,那就讓它建立一個圖書館。你創建一個應用程序併發布在github上,我將協作使其工作。

0

實現上述提到的最接近的解決方案是MaterialViewPager。這是一個很好的起點,您可以根據自己的偏好進行修改並修改,並且可以通過多種方式對其進行自定義。

+0

庫並沒有真正做我想做的庫似乎內置顯示信息的列表它沒有大量的返工做的,但它不是有用一個典型的「社交」應用程序。我想要在collapsingToolBarLayout下面使用textview的原因是因爲我可以提供與twitter應用程序相似的個人資料信息,而不需要用戶單擊任何地方以查看實際信息。應該有一種方法可以在代碼中實現它 - 這是一個廣泛使用和有用的概念。 – Simon