[英]Android Material Design AppBarLayout's attribute layout_scrollFlags problematic
[英]Material design layout_scrollFlags meanings
我發現我們可以使用很酷的標志,通過使用layout_scrollFlags
來滾動工具欄甚至內容。 就我而言,我有這樣的布局:
<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: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"
app:layout_scrollFlags="snap"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app: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"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
我的一個選項卡是一個fragment
,它的布局有一個Recycle View
,在Recycle View
下方有一個edittext
文本。 首先我想知道這個標志是什么意思
谷歌說:
我隨機更改了這個標志,在某些情況下,我的編輯文本消失了,直到我向上滾動工具欄然后編輯出現。 我閱讀了谷歌文檔,但我無法理解。 我想用簡單的術語來理解它。
我不知道我的答案是否仍然相關,但無論如何。 實際上,文檔足以理解正在發生的事情,您只需要稍微玩一下。
必須啟用屬性app:layout_scrollFlags
使用的scroll
標志才能使任何滾動效果生效。 此標志必須與enterAlways
、 enterAlwaysCollapsed
、 exitUntilCollapsed
或snap
一起啟用:
enterAlways
:向上滾動時視圖將變得可見。 當從列表底部滾動並希望在向上滾動時立即顯示工具欄時,此標志很有用。enterAlwaysCollapsed
:通常,當只使用 enterAlways 時,工具欄會隨着您向下滾動而繼續擴展。假設聲明了 enterAlways 並且您指定了 minHeight,您也可以指定 enterAlwaysCollapsed。 使用此設置時,您的視圖將僅出現在此最小高度處。 只有當滾動到達頂部時,視圖才會擴展到其全高exitUntilCollapsed
:設置滾動標志時,向下滾動通常會導致整個內容移動。通過指定 minHeight 和 exitUntilCollapsed,在其余內容開始滾動並退出屏幕之前將達到 Toolbar 的最小高度snap
:使用此選項將確定當視圖僅部分縮小時要執行的操作。 如果滾動結束並且視圖大小已減小到其原始大小的 50% 以下,則此視圖將返回到其原始大小。 如果尺寸大於其尺寸的 50%,它將完全消失。請看看這個博客,它應該真的很有幫助。
更新:還有另一篇關於滾動標志的文章(編輯:現在需要登錄到 Medium 帳戶) 。 非常感謝Martin Ombura Jr !
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.