Appbarlayout is a ViewGroup container component that inherits the Linerlayout implementation and is designed for the material design app Bar, which supports gesture swipe operations.
The default appbarlayout is vertically oriented, and its role is to appbarlayout the contents of the package as AppBar. The code layout is as follows:
<android.support.design.widget.AppBarLayout Android:id= "@+id/appbar"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"Android:background= "? Attr/colorprimary"Android:minheight= "? attr/actionbarsize" ></android.support.v7.widget.Toolbar> <android.support.design.widget.TabLayout Android:id= "@+id/tabs"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"App:layout_scrollflags= "Scroll"App:tabindicatorcolor= "@android: Color/holo_red_dark"App:tabselectedtextcolor= "@android: Color/holo_red_dark"App:tabtextcolor= "@android: Color/black"/></android.support.design.widget.appbarlayout>
The combined parts of toolbar and tablayout together form the AppBar effect here. Appbarlayout must be a parent layout container for toolbar. Appbarlayout support gesture sliding effect, to use with coordinatorlayout.
<?xml version= "1.0" encoding= "Utf-8"? ><android.support.design.widget.coordinatorlayout xmlns:android= " Http://schemas.android.com/apk/res/android "Xmlns:app= "Http://schemas.android.com/apk/res-auto"Android:id= "@+id/main_content"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" > <android.support.design.widget.AppBarLayout Android:id= "@+id/appbar"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"Android:background= "? Attr/colorprimary"App:layout_scrollflags= "Scroll|enteralways"/> <android.support.design.widget.TabLayout Android:id= "@+id/tabs"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"app:tabgravity= "Fill"/> </android.support.design.widget.AppBarLayout> <!--sliding layout content-<Android.support.v7.widget.RecyclerView Android:id= "@+id/recyclerview"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"App:layout_behavior= "@string/appbar_scrolling_view_behavior"/> <Android.support.design.widget.FloatingActionButton android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:src= "@drawable/ic_discuss"android:layout_gravity= "Bottom|end"/></android.support.design.widget.coordinatorlayout>
app:layout_scrollflags= the "Scroll|enteralways" property to determine which component is sliding. The properties of the Layout_scrollflags are
- Scroll: All view that wants to scroll out of the screen needs to be set this flag-the view without setting this flag will be pinned to the top of the screen.
- Enteralways: This flag allows any downward scrolling to cause the view to become visible, enabling quick "return mode".
- Enteralwayscollapsed: When your view has already set the MinHeight property and use this flag, your view can only be entered at the minimum height, and only when the scrolling view reaches the top will it expand to full height.
- Exituntilcollapsed: Scroll to exit the screen and finally fold at the top.
In order for the toolbar to slide, we must also have a condition, that is, coordinatorlayout the layout of a sliding layout, such as Viewpager,recyclerview,nestedscrollview (after testing, Listview,scrollview not supported) components that have a sliding effect. and set properties for these components, sliding toolbar can slide in the appbarlayout.
Android new Control appbarlayout use