Android Toolbar occupying all layout space

Asked

Viewed 193 times

1

I’m trying to carry out the implementation of a Toolbar in my Android application, but for some reason it takes up all screen space. I wonder why, since I am using the Below property in the layout after Toolbar.

activity_main.xml

<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"
    tools:context=".Main">

    <include
        android:id="@+id/tool_bar"
        layout="@layout/tool_bar"></include>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tool_bar">

        <LinearLayout
            android:id="@+id/llLogotipo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/imgLogotipo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/dmufscar" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/frmbotoes"
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:layout_below="@+id/llLogotipo"
            android:orientation="horizontal">

            <Button
                android:id="@+id/btnIniciarRFID"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:text="RFID" />

            <Button
                android:id="@+id/btnPatrimonio"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:text="@string/btnPatrimonio" />
        </LinearLayout>
    </RelativeLayout>

</RelativeLayout>

tool_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:elevation="4dp">


</android.support.v7.widget.Toolbar>

1 answer

2


In his file Toolbar.xml , make the following changes:

  1. Change the line android:layout_height="match_parent" for

    android:layout_height="wrap_content"    
    
  2. Add the following line:

    android:minHeight="?attr/actionBarSize"
    
  • Dear Jewel! It was right

Browser other questions tagged

You are not signed in. Login or sign up in order to post.