簡體   English   中英

Material design layout_scrollFlags 含義

[英]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文本。 首先我想知道這個標志是什么意思

谷歌說:

  • SCROLL_FLAG_ENTER_ALWAYS
    當進入(在屏幕上滾動)視圖將在任何向下滾動事件上滾動,無論滾動視圖是否也在滾動。
  • SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED
    'enterAlways' 的附加標志,它修改返回視圖以僅最初滾動回它的折疊高度。
  • SCROLL_FLAG_EXIT_UNTIL_COLLAPSED
    退出(滾動屏幕)時,視圖將滾動,直到它“折疊”。
  • SCROLL_FLAG_SCROLL
    視圖將與滾動事件直接相關。
  • SCROLL_FLAG_SNAP
    在滾動結束時,如果視圖只是部分可見,那么它將被捕捉並滾動到它最近的邊緣。

我隨機更改了這個標志,在某些情況下,我的編輯文本消失了,直到我向上滾動工具欄然后編輯出現。 我閱讀了谷歌文檔,但我無法理解。 我想用簡單的術語來理解它。

我不知道我的答案是否仍然相關,但無論如何。 實際上,文檔足以理解正在發生的事情,您只需要稍微玩一下。
必須啟用屬性app:layout_scrollFlags使用的scroll標志才能使任何滾動效果生效。 此標志必須與enterAlwaysenterAlwaysCollapsedexitUntilCollapsedsnap一起啟用:

  • 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM