3
A
回答
1
1
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
相關問題
- 1. Android:隱藏ActionBar,保持Tabs
- 2. 隱藏ActionBar,保持製表符不工作在Android Kikat
- 3. 刪除或禁用ActionBar隱藏動畫?
- 4. 如何隱藏表頭,並在插入/刪除後保持隱藏狀態
- 5. 如何隱藏Popup動畫?
- 6. 保持div顯示並隱藏舊的
- 7. 保持溢出:隱藏真的隱藏
- 8. jQuery顯示/隱藏動畫,保持對象的高度,直到動畫完成
- 9. 有沒有辦法禁用ActionBar的顯示/隱藏動畫?
- 10. 傳遞變量,並保持隱藏
- 11. 保持隱藏控制檯有效
- 12. Android:隱藏特定活動的ActionBar
- 13. 自動隱藏的ActionBar和ShareActionProvider
- 14. 延遲隱藏並顯示ActionBar?
- 15. 觸摸表面上的隱藏ActionBar
- 16. 如何隱藏動畫的TabPager佈局
- 17. 如何動畫/顯示隱藏的div?
- 18. 如何隱藏textarea但保持可見的插入符號?
- 19. 如何在ActionBar中隱藏ChromeCast MediaRoute MenuItem?
- 20. 如何完全隱藏ActionBar和NavigationBar
- 21. 如何在Xamarin.Forms中隱藏Android ActionBar?
- 22. 動畫CALayer隱藏
- 23. UIView動畫隱藏並顯示
- 24. Python - 如何隱藏標籤並保持傳說matplotlib?
- 25. 如何隱藏表面視圖中的視頻並保持音頻播放
- 26. 如何在隱藏時強制ExtJs面板保持寬度
- 27. 動畫@keyframes滑動頂部並保持
- 28. Android:如何隱藏某些活動的ActionBar
- 29. 保持導航欄隱藏
- 30. 如何顯示/隱藏div動畫?
如何是你的主要的佈局是什麼樣子?看來你只能改變工具欄的Y位置。我想知道列表視圖和toolbarcontainer的父級佈局及其關係。 – Gunhan
'ObservableListView'和工具欄容器都是sibilings,嵌套在同一個父代中。我在示例中添加了父佈局和「ObservableListView」。我希望它有幫助。 – memoizr
根據您的示例,scrollview的頂部位於工具欄下方。您是否使用工具欄的高度爲空白視圖添加了滾動視圖?或者您不需要像使用邊距或填充一樣來協調這個重疊部分? – Gunhan