Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material design layout_scrollFlags meanings

I find out that we can use cool flags that scroll both toolbar and even content by using layout_scrollFlags. In my case, I have a layout like this:

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

one of my tabs is a fragment and its layout has a Recycle View with a edittext below the RecycleView. firstly I wanna know what this flag means

google says:

  • SCROLL_FLAG_ENTER_ALWAYS
    When entering (scrolling on screen) the view will scroll on any downwards scroll event, regardless of whether the scrolling view is also scrolling.
  • SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED
    An additional flag for 'enterAlways' which modifies the returning view to only initially scroll back to it's collapsed height.
  • SCROLL_FLAG_EXIT_UNTIL_COLLAPSED
    When exiting (scrolling off screen) the view will be scrolled until it is 'collapsed'.
  • SCROLL_FLAG_SCROLL
    The view will be scroll in direct relation to scroll events.
  • SCROLL_FLAG_SNAP
    Upon a scroll ending, if the view is only partially visible then it will be snapped and scrolled to it's closest edge.

I changed this flag randomly and in some cases my edit text went away till I scrolled the toolbar up and then edit appeared. I read google documents but I could not get it well. I want to understand it in simple terms.

like image 848
Mahdi Avatar asked Feb 09 '16 07:02

Mahdi


People also ask

What is layout_scrollFlags?

And so, I will discuss app:layout_scrollFlags attribute from AppBarLayout.LayoutParams. This attribute is responsible for a scrolling behavior of AppBarLayout and its children. You can apply it directly to AppBarLayout or on the inside views, in the xml layout of your AppCompatActivity.

What is appbar layout in Android?

AppBarLayout is a vertical LinearLayout which implements many of the features of material designs app bar concept, namely scrolling gestures. Children should provide their desired scrolling behavior through AppBarLayout.

What is material Toolbar?

MaterialToolbar is a Toolbar that implements certain Material features, such as elevation overlays for Dark Themes and centered titles.

What is CollapsingToolbarLayout?

CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child of a AppBarLayout .


1 Answers

I don't know if my answer will still be relevant, but nevertheless. Actually docs are quite enough to understand things going around, you just need to play a little bit around.
The scroll flag used within the attribute app:layout_scrollFlags must be enabled for any scroll effects to take into effect. This flag must be enabled along with enterAlways, enterAlwaysCollapsed, exitUntilCollapsed, or snap:

  • enterAlways: The view will become visible when scrolling up. This flag is useful in cases when scrolling from the bottom of a list and wanting to expose the Toolbar as soon as scrolling up takes place.
  • enterAlwaysCollapsed: Normally, when only enterAlways is used, the Toolbar will continue to expand as you scroll down.Assuming enterAlways is declared and you have specified a minHeight, you can also specify enterAlwaysCollapsed. When this setting is used, your view will only appear at this minimum height. Only when scrolling reaches to the top will the view expand to its full height
  • exitUntilCollapsed: When the scroll flag is set, scrolling down will normally cause the entire content to move.By specifying a minHeight and exitUntilCollapsed, the minimum height of the Toolbar will be reached before the rest of the content begins to scroll and exit from the screen
  • snap: Using this option will determine what to do when a view only has been partially reduced. If scrolling ends and the view size has been reduced to less than 50% of its original, then this view to return to its original size. If the size is greater than 50% of its sized, it will disappear completely.

Please have a look at this blog it should be really helpful.

Update: Also there is another article (edit: now necessary to sign in to Medium account) about scroll flags. Big thanks to Martin Ombura Jr!

like image 149
Yurii Tsap Avatar answered Sep 30 '22 17:09

Yurii Tsap