How do I make the Toolbar do disappear when scrolling down? Currently it just disappear a bit. Should I use exitUntilCollapsed somewhat for make it work as I want? Or whats the different with CollapsingToolbarLayout?
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/toolbar"
app:layout_scrollFlags="scroll|enterAlways"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimaryDark"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:textColor="#color/whiteText"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/monthText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Month:"
android:textColor="#color/whiteText"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner_months"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/card_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
I want the Toolbar where CarLog is to be static but not the underlying.
I think you should use CoordinatorLayout to achieve that effect. Here is a working example
<?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.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="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
//your views here
</android.support.design.widget.CoordinatorLayout>
Related
I have a TabLayout with 4 tabs inside a Coordinator Layout and everytime I select the 4th tab, the toolbar gets hidden. That doesn't happen with the other tabs though. Similar issue occurs when I select an item from a dropdown menu inside the 3rd tab.
How can I avoid that and allow the toolbar to get hidden only if the user scrolls up (which is the default one)?
Thank you in advance for your help.
Here is my layout:
<android.support.constraint.ConstraintLayout 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:background="?attr/activity_background">
<android.support.design.widget.CoordinatorLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="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:layout_weight="1"
app:layout_scrollFlags="scroll|enterAlways">
</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:tabIndicatorColor="#color/text_hint"
app:tabIndicatorHeight="1dp">
<android.support.design.widget.TabItem
android:id="#+id/tabItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.TabItem
android:id="#+id/tabItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.TabItem
android:id="#+id/tabItem3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.TabItem
android:id="#+id/tabItem4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<fragment
android:name="com.example.Fragments.FabVerticalMenu"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
you can do something like this
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity.Main2Activity">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Your scrolling content -->
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="top"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
I want a ImageView to be between my toolbar and content (layouts with content).
Toolbar is not expandable.
How can I achieve this?
I do it in a such way:
<?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="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:titleTextAppearance="#style/AppTheme.ToolbarText" />
</android.support.design.widget.AppBarLayout>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.percent.PercentRelativeLayout
android:id="#+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/advantages_background"
app:layout_heightPercent="100%">
....
</android.support.percent.PercentRelativeLayout>
</android.support.percent.PercentRelativeLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/appBarLayout"
app:layout_anchorGravity="bottom|center">
<ImageView
android:id="#+id/fab"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/advantages_circle" />
...
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
I got this (toolbar overlaps my circle):
How can I fix it?
I want ImageView (my FrameLayout) to overlap Toolbar (anchor)
Add this line to framlayout
android:elevation="20dp"
add app:layout_behavior="#string/appbar_scrolling_view_behavior" into FrameLayout
<?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="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.percent.PercentRelativeLayout
android:id="#+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_blue_dark"
app:layout_heightPercent="100%" />
</android.support.percent.PercentRelativeLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/appBarLayout"
app:layout_anchorGravity="bottom|center"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ImageView
android:id="#+id/fab"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#mipmap/ic_launcher" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
if your want to overlap into toolbar then add app:behavior_overlapTop="20dp"
This will work if you change your AppBarLayout to a FrameLayout
<?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="wrap_content">
<FrameLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:titleTextAppearance="#style/AppTheme.ToolbarText" />
</FrameLayout>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.percent.PercentRelativeLayout
android:id="#+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/advantages_background"
app:layout_heightPercent="100%">
....
</android.support.percent.PercentRelativeLayout>
</android.support.percent.PercentRelativeLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/appBarLayout"
app:layout_anchorGravity="bottom|center">
<ImageView
android:id="#+id/fab"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/advantages_circle" />
...
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
.
This is what it would look like:
Add android:margineTop="?attr/actionBarSize" in your framlayout.
Good afternoon,
I am trying to place a (Relative?Linear?Frame?)Layout under the AppBar and the above the ViewPager, like in the Facebook Messenger App.
Like "TOUS, MESSENGER, SMS" in the picture below :
Here is the code I tried, but it does not work, the Layout is not shown under the AppBar.
<?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: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:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways|snap" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
app:tabIndicatorColor="#color/fullWhite"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<!-- This is the part I need to put between the AppBar and the content (ViewPager), but it is not shown -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content_frame">
<include layout="#layout/tous_messenger_sms"/>
</FrameLayout>
<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:background="#color/separator_color"/>
</android.support.design.widget.CoordinatorLayout>
And here is my "tous_messenger_sms" layout file (the problem is probably not that) :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_marginLeft="16sp"
android:layout_marginRight="16sp">
<Button
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="28sp"
android:id="#+id/tous_btn"
android:text="TOUS"
android:textColor="#color/colorPrimary"
android:layout_weight="1"
android:background="#drawable/button_shape_tous"
android:stateListAnimator="#null" />
<Button
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="28sp"
android:id="#+id/messenger_btn"
android:text="MESSENGER"
android:textColor="#color/colorPrimary"
android:layout_weight="1"
android:background="#drawable/button_shape_messenger"
android:stateListAnimator="#null" />
<Button
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="28sp"
android:id="#+id/sms_btn"
android:text="SMS"
android:textColor="#color/colorPrimary"
android:layout_weight="1"
android:background="#drawable/button_shape_sms"
android:stateListAnimator="#null" />
</LinearLayout>
Try this layout
<?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: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:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways|snap" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
app:tabIndicatorColor="#color/fullWhite"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<!-- This is the part I need to put between the AppBar and the content (ViewPager), but it is not shown -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/content_frame">
<include layout="#layout/tous_messenger_sms"/>
</FrameLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/separator_color" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
This is my layout file.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ActivityMain">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbarLayer"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<ListView
android:id="#+id/users"
android:layout_marginTop="40dp"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbarLayer"
android:layout_above="#+id/button_add_new_user"
/>
<Button
android:id="#+id/button_add_new_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add New User"
android:layout_alignParentBottom="true"
/>
</android.support.design.widget.CoordinatorLayout>
I want to display a button in bottom of the activity. but above code doesn't show a button.
Can anyone help me what is wrong here?
This will properly align your relative layout including Listview(above button) and button(parent bottom aligned) below toolbar.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbarLayer"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbarLayer"
android:layout_marginTop="?attr/actionBarSize"
>
<ListView
android:id="#+id/users"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button_add_new_user"
/>
<Button
android:id="#+id/button_add_new_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add New User"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Wrap your listview and button in a relativelayout like this:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ActivityMain">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbarLayer"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/users"
android:layout_marginTop="40dp"
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbarLayer"
android:layout_above="#+id/button_add_new_user"
/>
<Button
android:id="#+id/button_add_new_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add New User"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
It should work now.
<android.support.design.widget.AppBarLayout
android:id="#+id/toolbarLayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbarLayer">
<ListView
android:id="#+id/users"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button_add_new_user"
android:layout_marginTop="40dp"
android:padding="20dp" />
<Button
android:id="#+id/button_add_new_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Add New User" />
</RelativeLayout>
Use this code..
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbarLayer">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbarLayer"
android:layout_marginTop="?attr/actionBarSize"
>
<ListView
android:id="#+id/users"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button_add_new_user"
/>
<Button
android:id="#+id/button_add_new_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add New User"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#color/fragment.background">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/fragment.background"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/fragment.background"
android:orientation="vertical"
app:layout_scrollFlags="scroll|enterAlways">
<TextView
style="#style/merchantHintText"
android:id="#+id/contract_template_title"
android:layout_width="match_parent"
android:background="#color/white"
android:padding="15dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:src="#color/fragment.background" />
<com.tqmall.salestool.merchant.task.UploadImgLayout
android:id="#+id/contract_template_imglayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#color/white"
android:orientation="vertical"
android:padding="15dp" />
<TextView
android:id="#+id/contract_template_info"
style="#style/merchantHintText"
android:layout_width="match_parent"
android:background="#color/white"
android:padding="15dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:src="#color/fragment.background" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<com.tqmall.salestool.view.ListRecyclerView
android:id="#+id/contract_template_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:paddingBottom="40dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<TextView
android:id="#+id/contract_template_sure_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/text.red"
android:gravity="center"
android:padding="10dp"
android:textColor="#color/white"
android:textSize="20sp" />
</RelativeLayout>
When my adapter have enough number of data (which inflating a much higher view than screen), the LinearLayout in AppBarLayout will collapse correctly. However, if there are few data, it will not collapse. I read the source code of AppBarLayout, but not find the code cause that.
Why it acts like that?
Just put you Linear layout into CollapsingToolbarLayout like this
<?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:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- views -->
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/scrollableView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Try this. It should work.