Search code examples
androidlayoutnavigationbar

Layout doesn't take up whole screen


I am trying to render my activity_main under my navigation bar using <item name="android:windowTranslucentNavigation">true</item> in my styles.xml and by adding android:fitsSystemWindows="true" into my layouts. For some reason instead of using all space available, the layout centers itself into the available space:

[![enter image description here][1]][1]

my main_activity:

<?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="com.example.smc_kr.gachi_soundboardv2.MainActivity">

    <android.support.design.widget.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>

    <include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>

my content_main:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_main"
    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"
    android:fitsSystemWindows="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.smc_kr.gachi_soundboardv2.MainActivity"
    tools:showIn="@layout/activity_main">

    <GridView
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:id="@+id/gridview"
        android:numColumns="auto_fit"
        android:verticalSpacing="0dp"
        android:horizontalSpacing="0dp"
        android:gravity="center"
        android:stretchMode="columnWidth"
        android:columnWidth="100dp">
    </GridView>
</RelativeLayout>

my styles 21:

<resources>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>
</resources>

All dimension values are set to 0dp. Am i missing something here?


Solution

  • I fixed this by replacing the RelativeLayout in content_main with a ScrimInsetsFrameLayout.