Layout Hierarchy

0

I want my Toolbar that I put in ActionBar's place not to be inside ScroolView, but always when I shoot it and create a RelativeLayout or LinearLayout on the outside and put the Toolbar and then ScroolView it does not appear.

This is my current XML:

<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:layout_width="match_parent"
    android:layout_height="match_parent">


    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView"
        style="@style/FundoAPP"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="right">


        <LinearLayout 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="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:weightSum="1"
            tools:context="com.example.joel.housepharm.ClasseTelas.InsProgramacao">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbarSessao"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="?attr/colorPrimary"
                android:minHeight="?attr/actionBarSize">

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


            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:paddingTop="24dp">

                <ScrollView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ListView
                            android:id="@+id/JN_04_06"
                            android:layout_width="210dp"
                            android:layout_height="190dp"
                            android:layout_alignParentLeft="true"
                            android:layout_alignParentStart="true"
                            android:layout_centerVertical="true"
                            android:divider="@color/colorAccentSecurdary" />

                        <ListView
                            android:id="@+id/JN_04_07"
                            android:layout_width="140dp"
                            android:layout_height="190dp"
                            android:layout_alignParentEnd="true"
                            android:divider="@color/colorAccentSecurdary" />
                    </RelativeLayout>
                </ScrollView>
            </android.support.design.widget.TextInputLayout>
            <!--style="@style/CamposImput"-->


            <!--
            <RelativeLayout
                android:layout_height="fill_parent"
                android:layout_width="fill_parent"
                android:gravity="center_horizontal">
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/cancelar"
                    android:id="@+id/JN_04_11"
                    android:onClick="JN_04_Fechar"
                    style="@style/Botoes"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/confirma"
                    android:id="@+id/JN_04_12"
                    android:onClick="clickBtnProg"

                    style="@style/Botoes"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true" />

            </RelativeLayout>
            -->
            <View style="@style/Divider" />

            <TextView
                style="@style/Textos"
                android:layout_width="match_parent"

                android:layout_height="match_parent"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:paddingTop="24dp"
                android:text="@string/Repet" />

            <RadioGroup
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:paddingTop="24dp">

                <CheckBox
                    android:id="@+id/chkUmaVez"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="true"
                    android:text="@string/somenteUma" />

                <CheckBox
                    android:id="@+id/chkTodosDias"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="false"
                    android:text="@string/todosDias" />

                <RelativeLayout
                    android:layout_width="193dp"
                    android:layout_height="match_parent">

                    <TextView
                        android:id="@+id/textView"
                        style="@style/Textos"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentStart="true"
                        android:layout_centerVertical="true"
                        android:text="@string/Repetir"
                        android:textAppearance="?android:attr/textAppearanceMedium" />

                    <EditText
                        android:id="@+id/horasRep"
                        android:layout_width="30dp"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="true"
                        android:layout_marginLeft="10dp"
                        android:layout_marginRight="10dp"
                        android:layout_toEndOf="@+id/textView"
                        android:ems="2"
                        android:inputType="number"
                        android:maxLength="2"
                        android:maxLines="1"
                        android:textAlignment="center" />

                    <TextView
                        android:id="@+id/textView22"
                        style="@style/Textos"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/textView"
                        android:layout_toEndOf="@+id/horasRep"
                        android:text="@string/horas"
                        android:textAppearance="?android:attr/textAppearanceMedium" />
                </RelativeLayout>
            </RadioGroup>

            <TextView
                android:id="@+id/textView12"
                style="@style/Textos"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:paddingTop="24dp"
                android:text="@string/CampoObrigatorio"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/colorAccent" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

This is the new one, that the Toolbar does not appear:

<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:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbarSessao"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize">

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

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView"
        style="@style/FundoAPP"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="right">


        <LinearLayout 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="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:weightSum="1"
            tools:context="com.example.joel.housepharm.ClasseTelas.InsProgramacao">



            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:paddingTop="24dp">

                <EditText
                    android:id="@+id/JN_04_01"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="15dp"
                    android:hint="@string/hintHora"
                    android:textColorHint="#ffa3a3a3" />


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

            <TextView
                android:id="@+id/textView2"
                style="@style/Textos"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:paddingTop="24dp"
                android:text="@string/RemSess"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <fr.ganfra.materialspinner.MaterialSpinner
                android:id="@+id/JN_04_02"
                style="@style/SinnerMaterialDesign"
                android:layout_width="340dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                app:ms_enableErrorLabel="false"
                app:ms_enableFloatingLabel="false"
                app:ms_multiline="false"
                app:ms_thickness="1dp">

            </fr.ganfra.materialspinner.MaterialSpinner>
            <!--
            <Spinner
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/JN_04_02"
                style="@style/Widget.AppCompat.Light.DropDownItem.Spinner"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:background="@drawable/abc_spinner_mtrl_am_alpha"
                android:spinnerMode="dialog" />
    -->
            <!--<TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="@string/QtdDos"
                android:id="@+id/textView3"
                style="@style/Textos"
                android:layout_marginTop="15dp" />
    -->
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:paddingTop="24dp">

                <EditText
                    android:id="@+id/JN_04_03"
                    android:layout_width="97dp"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:hint="Doses*"
                    android:inputType="numberDecimal" />
            </android.support.design.widget.TextInputLayout>

            <!--style="@style/CamposImput"-->

            <View

                style="@style/Divider" />

            <RelativeLayout xmlns:custom="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:gravity="center_horizontal">

                <Button
                    android:id="@+id/btnAdd"
                    android:layout_width="120dp"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_marginEnd="5dp"
                    android:layout_toStartOf="@+id/btnRemove"
                    android:background="@color/cardview_light_background"
                    android:singleLine="false"
                    android:text="@string/ADD"
                    android:textColor="@color/colorPrimary" />
                <!--<com.getbase.floatingactionbutton.FloatingActionButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/btnAdd"
                    fab:fab_colorNormal="#ffffff"
                    fab:fab_colorPressed="#ffffff"
                    fab:fab_size="normal"
                    fab:fab_icon="@drawable/ic_action_confirm"

                    />
                    -->
                <Button
                    android:id="@+id/btnRemove"
                    android:layout_width="120dp"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:background="@color/colorAccent"

                    android:text="@string/REMOVE"
                    android:textColor="@color/colorTextButton" />
            </RelativeLayout>


            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:paddingTop="24dp">

                <ScrollView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <ListView
                            android:id="@+id/JN_04_06"
                            android:layout_width="210dp"
                            android:layout_height="190dp"
                            android:layout_alignParentLeft="true"
                            android:layout_alignParentStart="true"
                            android:layout_centerVertical="true"
                            android:divider="@color/colorAccentSecurdary" />

                        <ListView
                            android:id="@+id/JN_04_07"
                            android:layout_width="140dp"
                            android:layout_height="190dp"
                            android:layout_alignParentEnd="true"
                            android:divider="@color/colorAccentSecurdary" />
                    </RelativeLayout>
                </ScrollView>
            </android.support.design.widget.TextInputLayout>
            <!--style="@style/CamposImput"-->


            <!--
            <RelativeLayout
                android:layout_height="fill_parent"
                android:layout_width="fill_parent"
                android:gravity="center_horizontal">
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/cancelar"
                    android:id="@+id/JN_04_11"
                    android:onClick="JN_04_Fechar"
                    style="@style/Botoes"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/confirma"
                    android:id="@+id/JN_04_12"
                    android:onClick="clickBtnProg"

                    style="@style/Botoes"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true" />

            </RelativeLayout>
            -->
            <View style="@style/Divider" />

            <TextView
                style="@style/Textos"
                android:layout_width="match_parent"

                android:layout_height="match_parent"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:paddingTop="24dp"
                android:text="@string/Repet" />

            <RadioGroup
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:paddingTop="24dp">

                <CheckBox
                    android:id="@+id/chkUmaVez"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="true"
                    android:text="@string/somenteUma" />

                <CheckBox
                    android:id="@+id/chkTodosDias"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="false"
                    android:text="@string/todosDias" />

                <RelativeLayout
                    android:layout_width="193dp"
                    android:layout_height="match_parent">

                    <TextView
                        android:id="@+id/textView"
                        style="@style/Textos"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentStart="true"
                        android:layout_centerVertical="true"
                        android:text="@string/Repetir"
                        android:textAppearance="?android:attr/textAppearanceMedium" />

                    <EditText
                        android:id="@+id/horasRep"
                        android:layout_width="30dp"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="true"
                        android:layout_marginLeft="10dp"
                        android:layout_marginRight="10dp"
                        android:layout_toEndOf="@+id/textView"
                        android:ems="2"
                        android:inputType="number"
                        android:maxLength="2"
                        android:maxLines="1"
                        android:textAlignment="center" />

                    <TextView
                        android:id="@+id/textView22"
                        style="@style/Textos"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/textView"
                        android:layout_toEndOf="@+id/horasRep"
                        android:text="@string/horas"
                        android:textAppearance="?android:attr/textAppearanceMedium" />
                </RelativeLayout>
            </RadioGroup>

            <TextView
                android:id="@+id/textView12"
                style="@style/Textos"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
                android:paddingRight="?android:attr/listPreferredItemPaddingRight"
                android:paddingTop="24dp"
                android:text="@string/CampoObrigatorio"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/colorAccent" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>
    
asked by anonymous 15.01.2016 / 22:23

1 answer

1

First, let's understand what's going on with your layout.

When you use RelativeLayout , you are putting your components together, and then telling them how they should behave (via attributes like toRightOf or alignParentRight etc.).

In your case, you are putting your Toolbar and then placing your ScrollView .

Basically, what's happening is that your Toolbar is behind of your ScrollView , which explains why it is not appearing on the screen. Remember that the order you declare the components in your xml, will be the order that your RelativeLayout will draw / lay out. In other words: first your Toolbar and then, above all, your ScrollView .

You have a few ways to solve this, the first less being indicated and the last more indicated:

1) You can lay out your layout in a different way: first setting your ScrollView and then its Toolbar eg

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView .../>

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

</RelativeLayout>

2) You can keep your layout the way it is and define how your components will behave, ie setting the attributes that will define how your components will position themselves within your RelativeLayout : setting the android:layout_below="" attribute % in its ScrollView , telling it to position below from another layout (id), for example

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar 
        android:id="@+id/toolbar"
        .../>

    <ScrollView 
        ...
        android:layout_below="@+id/toolbar"/>

</RelativeLayout>

3) You can replace your RelativeLayout with a LinearLayout with the vertical orientation. This will make your layout be constructed in a linear fashion and respect the order. Assigning the android:layout_weight="1" attribute, you will ensure that your ScrollView will occupy any size it will need:

<?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.v7.widget.Toolbar
        android:id="@+id/toolbar" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1">
        ...
    </ScrollView>

</LinearLayout>
    
16.01.2016 / 00:14