It seems that this question was asked many times before. At least i found a lot on the internet and SO in particular. But none of the answers helped, don't know why.
I've created a simple blank tabbed activity project in Android Studio 2.2.2 Haven't touched anything in it except one addition - adding an imageview. Here is an activity layout, which was generated:
<?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.company.me.navbartest.MainActivity">
<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.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:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</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.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
Didn't change anything here. And here is a fragment's layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.company.me.navbartest.MainActivity$PlaceholderFragment">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_alignParentBottom="true"
android:src="@mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
The only addition here is an ImageView at the bottom of the fragment. Didn't touch the code at all. Don't know if it's needed, but just in case it's here: http://pastebin.com/FuUiGpyH
This was taken on KitKat but it's same on Marshmallow. See the small green ears? That's from the ImageView i've added. It's an icon of an android logo.
I've tried different combinations of "fitsSystemWindows" flag. No success. I guess i just don't quite understand how it works and should be used.
Also tried changing the root object of the fragment - same results.
So the main question is - how to fix this? How to make sure this ImageView is shown where it was supposed to?
The gradle specs are:
minSdkVersion 19
targetSdkVersion 25
compileSdkVersion 25
buildToolsVersion "25.0.0"
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'