I want to modify the size of CollapsingToolbarLayout
it so that there is not so much space between the three menu points and the main bar.
And what I want is to "remove" or decrease the pink bar (colorAccent) as in the following image:
This is the code of theLayout
<?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="recyclerview.ejemplo.aldakur.net.ejemplorecyclerview.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/parallax_collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
app:contentScrim="?attr/colorPrimary"
android:background="@color/colorAccent">
<ImageView
android:id="@+id/parallax_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/images"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="@+id/parallax_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!--<include layout="@layout/content_main" />-->
<android.support.v7.widget.RecyclerView
android:id="@+id/parallax_rv"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/parallax_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
Edit: In Android 4.1 it is displayed correctly, but not in Android 6.0
Seeing that the space of the pink color is equal to the height of the statusbar.
To make the elements draw below the
StatusBar
you must assign the property you want toandroid:fitsSystemWindows="true"
In order for it to
fitSystemWindows
take effect, you must first assign the following to the topic of the activityvalues-21/styles.xml
:update
The
wrap_content
doesn't work quite right on images within theCollapsingToolbarLayout
The images, if not specified otherwise, android displays them so that they fit inside the view, to adjust them I use the library
glide
or by code I define the height of theAppBarLayout
Your code
AppBarLayout
defines200dp
height, where you havewrap_content
putmatch_parent
and addandroid:fitsSystemWindows="true"
to all the elements you want to start from the absolute top.Try that code:
Your implementation of
CollapsingToolbarLayout
is correct, rather I think that your image is smaller than the size ofAppBarLayout
which is of200dp
, and that is why the color ofbackground
orcontentScrim
configured in yourCollapsingToolbarLayout