Android Coordinatorlayout + appbarlayout (scroll up to hide specified view)

Source: Internet
Author: User

In the new Android support Library, added Coordinatorlayout, appbarlayout and so on.

Effect: Scroll down recylerview,tab will be hidden, scroll up recylerview,tab recovery appears. The advantage of this is that users have more space to look at the contents of the list.

<?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:layout_width="match_parent"Android:layout_height="match_parent"android:orientation="Vertical"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent"Android:layout_height="wrap_content"android:orientation="Vertical"> <Android.support.v7.widget.Toolbar Android:id="@+id/third_activity_toolbar"Android:layout_width="match_parent"Android:layout_height="? attr/actionbarsize"/> <android.support.design.widget.TabLayout Android:id="@+id/tab_layout"Android:layout_width="match_parent"Android:layout_height="wrap_content"App:layout_scrollflags="scroll|enteralways"App:tabindicatorcolor="@color/medium_blue"App:tabselectedtextcolor="@color/medium_blue"app:tabtextappearance="@style/tabtext"App:tabtextcolor="@color/gray_text"/> </android.support.design.widget.AppBarLayout> <Android.support.v4.view.ViewPager Android:id="@+id/viewpager"Android:layout_width="match_parent"Android:layout_height="wrap_content"App:layout_behavior="@string/appbar_scrolling_view_behavior"/></android.support.design.widget.coordinatorlayout>

1) First need to use Coordinatorlayout to wrap the appbarlayout;

2) The view of the top area is placed inside the appbarlayout;

3) Appbarlayout outside, coordinatorlayout inside, put a scrollable view. As the example above, put the Viewpager, and Viewpager inside is put Recylerview, that is, you can scroll the view.

4) in the Appbarlayout view, through the App:layout_scrollflags properties to control, scrolling when the performance. There are 4 types of flag.

    • scroll: This flag should is set for any views that want to scroll off the screen-for views that does not use this flag, they ' ll Remain pinned to the top of the
    • enterAlways: This flag ensures if any downward scroll would cause this view to become visible, enabling the ' Quick return ' pattern
    • enterAlwaysCollapsed: When your view have declared a minheight and you use the this flag, your view would only enter at its minimum height (i.e., ' C Ollapsed '), only re-expanding to its full height when the scrolling view has reached it ' s top.
    • exitUntilCollapsed: This flag causes the view to scroll off until it was ' collapsed ' (its minheight) before exiting

The examples above are scroll and enteralways.

Scroll indicates that when scrolling down, the view is scrolled out of the screen until it is hidden.

Enteralways indicates that when scrolling up, the view appears as a scrolling gesture until the original position is restored.

5) Set the property App:layout_behavior on the view that can be scrolled.

The value of this property is actually a complete class name, and the @string/appbar_scrolling_view_behavior in the example above is a value that is defined by the Android support Library and can be used directly.

This behavior class is really a scrolling behavior that controls the scrolling time of the view. We can also inherit the behavior class to implement the unique scrolling behavior.

6) in the Code section, you only need to implement Recylerview logic.

Android Coordinatorlayout + appbarlayout (scroll up to hide specified view)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.