回答

1

大;) 以下是另一個小提示: 爲選項卡使用分離佈局或將它們集成到工具欄中,然後僅轉換工具欄只要你能看到頂部的標籤。

5

正如其他人所建議的,使用ObservableScrollView來自:https://github.com/ksoichiro/Android-ObservableScrollView

嘗試把兩個Toolbar並在同一容器中SlidingTabStrip,然後動態顯示容器作爲用戶滾動ObservableScrollView,例如:

<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" 
     tools:context=".MainActivity"> 

    <com.github.ksoichiro.android.observablescrollview.ObservableListView 
     android:id="@+id/listView" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent"/> 

    <LinearLayout 
     android:id="@+id/toolbarContainer" 
     android:orientation="vertical" 
     android:elevation="10dp" 
     android:background="@color/material_deep_teal_200" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize"/> 

      <!--Placeholder view, your tabstrip goes here--> 
      <View 
       android:layout_width="wrap_content" 
       android:layout_height="48dp"/> 
    </LinearLayout> 
</FrameLayout> 

然後當你覆蓋ObservableScrollViewCallbacks時,你可以這樣做:

@Override 
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { 

    toolbarContainer.animate().cancel(); 

    int scrollDelta = scrollY - oldScrollY; 
    oldScrollY = scrollY; 

    float currentYTranslation = -toolbarContainer.getTranslationY(); 
    float targetYTranslation = Math.min(Math.max(currentYTranslation + scrollDelta, 0), toolbarHeight); 
    toolbarContainer.setTranslationY(-targetYTranslation); 
} 

@Override 
public void onUpOrCancelMotionEvent(ScrollState scrollState) { 
    float currentYTranslation = -toolbarContainer.getTranslationY(); 
    int currentScroll = listView.getCurrentScrollY(); 

    if (currentScroll < toolbarHeight) { 
     toolbarContainer.animate().translationY(0); 
    } else if (currentYTranslation > toolbarHeight /2) { 
     toolbarContainer.animate().translationY(-toolbarHeight); 
    } else { 
     toolbarContainer.animate().translationY(0); 
    } 
} 

onUpOrCancelMotionEvent東西是動畫容器,以防止在工具欄從僅爲一半示出/隱藏。

這裏有一個演示視頻僅供參考:https://drive.google.com/file/d/0B7TH7VeIpgSQSzZER1NneWpYa1E/view?usp=sharing

+0

如何是你的主要的佈局是什麼樣子?看來你只能改變工具欄的Y位置。我想知道列表視圖和toolbarcontainer的父級佈局及其關係。 – Gunhan

+0

'ObservableListView'和工具欄容器都是sibilings,嵌套在同一個父代中。我在示例中添加了父佈局和「ObservableListView」。我希望它有幫助。 – memoizr

+0

根據您的示例,scrollview的頂部位於工具欄下方。您是否使用工具欄的高度爲空白視圖添加了滾動視圖?或者您不需要像使用邊距或填充一樣來協調這個重疊部分? – Gunhan