Search code examples
androidxmlandroid-appbarlayoutappbar

AppBar wrong height


My AppBar is doing weird things. This is what it looks like on a 720x1280 screen: enter image description here

It is how it's supposed to look like. And this is how it looks like on a 1080x1920 screen: enter image description here I was playing around with the toolbar height in the app_bar_main.xml, but I didn't like it, so I set it back to the default ?attr/actionBarSize value. What could be the problem? Here is my app_bar_main.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"
android:fitsSystemWindows="true"
tools:context="com.koostamas.justtry.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>

</android.support.design.widget.CoordinatorLayout>

And here is my activity_main.xml:

<?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="match_parent"
android:orientation="vertical" >

<include
    android:id="@+id/app_bar"
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/containerView">
    </FrameLayout>


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/drawerPane"
        android:layout_gravity="start">

        <!-- List of Actions (pages) -->
        <ListView
            android:id="@+id/navList"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:choiceMode="singleChoice"
            android:background="@color/busblue"/>

    </RelativeLayout>

</android.support.v4.widget.DrawerLayout>

</LinearLayout>

Solution

  • try update your code. As of me this issue is with your views.Your approach is not correct to add this. If you are including the Toolbar only then whats the need of coordinateLayout and AppBarLayout!

    update app_bar_main.xml ocde with this

    <?xml version="1.0" encoding="utf-8"?>
    <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" />
    

    update your activity_main.xml code with this

    <?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="match_parent"
        android:orientation="vertical">
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <include
            android:id="@+id/app_bar"
            layout="@layout/app_bar_main" />
    
        <FrameLayout
            android:id="@+id/containerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"></FrameLayout>
    
        <RelativeLayout
            android:id="@+id/drawerPane"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start">
    
            <!-- List of Actions (pages) -->
            <ListView
                android:id="@+id/navList"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:background="@color/busblue"
                android:choiceMode="singleChoice" />
    
        </RelativeLayout>
    
    </android.support.v4.widget.DrawerLayout>