Android - Unable to fix the Toolbar in a Collapsing Toolbar layout - java

I am currently using CollapsingToolbar Layout in the upper portion of my layout. I want to collpase a particular portion (LinearLayout only) and keep the toolbar fixed on the top. I was able to fix the Toolbar position on top in another project and keep it from collapsing. However, for some reason, I am not able to fix the position of my toolbar. Any help will be appreciated. Here is my the XML of the 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:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/profile_coordinate_layout"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
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:layout_scrollFlags="scroll|enterAlways"
android:layout_gravity="fill_vertical"
android:fitsSystemWindows="true"
app:layout_collapseMode="pin"
app:expandedTitleMarginStart="?actionBarSize"
app:contentScrim="?colorPrimary"
>
<!--|||||||||||||||||||||||||||||||||||||||||||||||||-->
<!--|||||||||||||||Collection Profile and about||||||-->
<!--|||||||||||||||||||||||||||||||||||||||||||||||||-->
<LinearLayout
android:id="#+id/ll_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?actionBarSize"
android:orientation="vertical"
app:layout_collapseMode="pin"
android:background="#drawable/gradient_feed_bg"
>
<include
layout="#layout/item_collection_profile" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="#drawable/dark_primary_no_radius"
app:layout_collapseMode="pin"
android:elevation="#dimen/margin_4dp"
>
<include layout="#layout/action_bar_collection_profile"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
></android.support.v4.view.ViewPager>
</android.support.design.widget.CoordinatorLayout>
I am loading another fragment on the ViewPager. and I am using the following code to load the toolbar.
findViewById(R.id.toolbar). setBackgroundResource(R.drawable.dark_primary_no_radius);
setSupportActionBar((android.support.v7.widget.Toolbar)findViewById(R.id.toolbar));
And here is UPDATED the result:
As you can see, in the second image, toolbar collapsed on the top. Any help will be highly appreciated.
Thank you.

You need to use the app:layout_collapseMode="pin" in Toolbar only.
Remove this from other components like the LinearLayout and CollapsingToolbarLayout.
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
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:layout_scrollFlags="scroll|exitUntilCollapsed"
android:layout_gravity="fill_vertical"
android:fitsSystemWindows="true"
app:expandedTitleMarginStart="?actionBarSize"
app:contentScrim="?colorPrimary"
>
<!--|||||||||||||||||||||||||||||||||||||||||||||||||-->
<!--|||||||||||||||Collection Profile and about||||||-->
<!--|||||||||||||||||||||||||||||||||||||||||||||||||-->
<LinearLayout
android:id="#+id/ll_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?actionBarSize"
android:orientation="vertical"
app:layout_collapseMode="parallax"
android:background="#drawable/gradient_feed_bg"
>
<include
layout="#layout/item_collection_profile" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="#drawable/dark_primary_no_radius"
app:layout_collapseMode="pin"
android:elevation="#dimen/margin_4dp"
>
<include layout="#layout/action_bar_collection_profile"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>

Related

Part of Linear Layout hide under Action bar

I know this may be a stupid question, however as a newbie i cant get to work around it.
So i want to add actionBar with Back Navigation Button and part of LinearLayout is hidden. How could i solve the problem ??
Code
MainActivity.xml
<?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=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:elevation="4dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:navigationIcon="#drawable/ic_arrow_back_black_24dp"/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
Content Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main"
>
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_productname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="15"
app:errorEnabled="true">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Product Name"
android:inputType="text"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Price"
android:inputType="numberDecimal|numberSigned"/>
</android.support.design.widget.TextInputLayout>
<!--Add Product-->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Product"
android:onClick="addProduct"/>
</LinearLayout>
Expectation
I manually set margin-top to lower Linearlayout and show the expected result.
You need to add the layout behaviour to your content
<include layout="#layout/content_main"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
You can try this. Since you are using CoordinatorLayout you need to use layout_behaviour, layout_anchor and layout_anchorGravity to properly align the layout. Just add the following line in your include:
app:layout_behavior="#string/appbar_scrolling_view_behavior"
So it will be like this:
<include layout="#layout/content_main"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>

SwipeRefreshLayout not working with empty List

My app contains a SwipeRefreshLayout with a listView inside of it. The list receives data from a server. So when the data is fetched and the list is populated correctly the swipe to refresh works, but when the data is not passed to the list and is empty the SwipeRefresh doesn’t work. Why can’t I swipe when the listView is empty?
That‘s my layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/colorGrayHell"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="140dp"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:expandedTitleMarginBottom="56dp"
app:contentScrim="#color/colorPrimary"
app:expandedTitleGravity="bottom|center"
app:expandedTitleTextAppearance="#style/CollBar"
app:title="Tankstellen"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="#+id/toolbar">
<ImageView
android:id="#+id/backg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="#drawable/backthree"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginBottom="48dp"
app:layout_collapseMode="pin"
android:layout_gravity="bottom"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="55dp">
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginTop="10dp"
android:background="#android:color/white"
android:divider="#color/colorGrayHell"
android:dividerHeight="10dp"
android:nestedScrollingEnabled="true" />
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Your listview and the swipe refresh layout is within a nested scroll view which means the height of child of the nested scroll view becomes wrap content (Relative layout in your case) automatically (It also might be showing you a lint warning to replace the match parent height of your relative layout to wrap content).
therefore when there's no data in your list, the height of the whole layout group becomes 0 and the place where you need to swipe to refresh has a height of 0 and you cant swipe within a layout of height zero.
To solve this you can take a linear layout above your nested scroll view with the height of match parent and put your swipe refresh layout over it.
Let me know if you need the example code.
EDIT
Okay! so this is a workaround I found to solve the issue. You can try this and please let me know if this solves your problem.
The Idea is to wrap everything a swipe refresh layout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent">
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:background="#color/colorGrayHell"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="140dp"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:expandedTitleMarginBottom="56dp"
app:contentScrim="#color/colorPrimary"
app:expandedTitleGravity="bottom|center"
app:expandedTitleTextAppearance="#style/CollBar"
app:title="Tankstellen"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="#+id/toolbar">
<ImageView
android:id="#+id/backg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="#drawable/backthree"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginBottom="48dp"
app:layout_collapseMode="pin"
android:layout_gravity="bottom"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="55dp">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginTop="10dp"
android:background="#android:color/white"
android:divider="#color/colorGrayHell"
android:dividerHeight="10dp"
android:nestedScrollingEnabled="true" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</android.support.v7.widget.LinearLayoutCompat>
</android.support.v4.widget.SwipeRefreshLayout>

Collapsing Toolbar is not scrollable

I‘m trying to create an app containing a collapsing toolbar. Below is the layout of my XML file. The intention was to make it collapsing but with my code everything is just fixed to its current position and not scrollable at all. Hope anyone has any suggestions.
As information: I’m using android studio and the system runs at API 26
<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"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.te.e5.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_height="300dp"
android:layout_width="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/coltoolbar"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_scrollFlags="exitUntilCollapsed|scroll"
app:contentScrim="?attr/colorPrimary"
app:title="App Title"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:background="#drawable/materialbackground">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarid"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Change the flags sequence in CollapsingToolbarLayout like this
app:layout_scrollFlags="scroll|exitUntilCollapsed"
if you want the collapsing toolbar to scroll when user scrolls content then the first flag should be "scroll" always then "exitUntilCollapsed".
Solution:
<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="com.birjuvachhani.myapplication.ScrollingActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="#+id/toolbar">
<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/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" >
<!-- Main content goes here. -->
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

Toolbar menu not showing up

I have a requirement to show bottom navigation view, drawer menu in same layout.
Bottom navigation has three tabs each has its own content.The first bottom navigation tab contains a view pager with tablayout that has some conflict with the parent toolbar.
Problem
The child fragment toolbar hides the parent toolbar menu ☰ icon.
Here is the layout I am using.
ParentLayout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.HomeActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="6dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:elevation="0dp"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="#menu/navigation" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/menu_drawer" />
</android.support.v4.widget.DrawerLayout>
BottomNavFragment1.xml
<?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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.telenor.magri.saatdo.activities.TabbedActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.NoActionBar.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.NoActionBar.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill"
app:tabIndicatorColor="#color/colorPrimaryDark"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
ScreenShot : Child layout having tablayout
ScreenShot : Child layout not having tablayout
But the problem is toolbar menu icon for drawer is not showing up its hiding behind the child toolbar. So any idea what is problem in my layout.
Thanks
You are overriding the Parent Activity toolbar in your Bottom Navigation View- Fragment 1
Change your layout to remove the toolbar..
BottomNavFragment1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
app:tabGravity="fill"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3b5998"
android:minHeight="?attr/actionBarSize"
app:tabIndicatorColor="#c8130d"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
</LinearLayout>
EDIT
In your activity layout use layout_below attribute for your FrameLayout
ParentLayout.xml
<FrameLayout
android:id="#+id/container"
android:layout_below = "#+id/appBarLayout" //add this
android:layout_width="match_parent"
android:layout_height="match_parent" />
otherwise it will replace the whole layout including the toolbar in your parent.

Views appearing on top of collapsing toolbar

EDIT: Problem solved. See Blackbelt's comment
I've been trying to implement the collapsing toolbar into my project, sticking to an example provided by Google. I've gotten it to work for the most part, but views are appearing on top of the toolbar rather than below them.
Below, I've pasted the XML code for the activity that hosts the toolbar.
<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="android.jochemkleine.com.popularmovies.ui.MovieDetailActivity"
android:background="#57ffffff">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="#dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
android:id="#+id/toolbarImage"
/>
<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/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/item_detail_container">
</FrameLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/btn_star_big_off"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end"
android:scaleType="center"
app:backgroundTint="#ffffff"/>
Note that the FrameLayout with id item_detail_container will contain a fragment.
Said fragment uses to the following XML file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_movie_details"
tools:context="android.jochemkleine.com.popularmovies.ui.m"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TEXTVIEW"
/>
</LinearLayout>
Note that right now, the LinearLayout in this XML file serves no purpose at all, because there is only one TextView present. It will however be of use later, as NestedScrollView can only host one direct child.
I am fairly sure that the fault lies somewhere within the first XML file, likely with the use of the FrameLayout. What baffles me is that the Google example does it almost exactly the same way, the only difference is that they include a layout, instead of using a FrameLayout.
Thanks in advance; any and all help is appreciated.

Categories