0

Quero que a minha Toolbar que coloquei no lugar da ActionBar não fique dentro da ScroolView, porem sempre quando tiro ela e crio um RelativeLayout ou LinearLayout por fora e coloco a Toolbar e depois a ScroolView ela não aparece.

Essa é minha XML atual:

<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>

Essa é a nova, que a Toolbar não aparece:

<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>

1 Resposta 1

1

Primeiro, vamos entender o que está acontecendo com seu layout.

Quando você utiliza o RelativeLayout, você está colocando os seus componentes todos juntos, e depois dizendo como eles devem se comportar (via atributos como toRightOf ou alignParentRight etc.).

No seu caso, você está colocando sua Toolbar e logo em seguida colocando seu ScrollView.

Basicamente, o que está acontecendo é que sua Toolbar está por trás do seu ScrollView, o que explica ela não estar aparecendo na tela. Lembre-se que, a ordem que você declarar os componentes em seu xml, vai ser a ordem que seu RelativeLayout irá desenhar/dispor. Em outras palavras: primeiro sua Toolbar e depois, por cima, seu ScrollView.

Você tem algumas maneiras de resolver isso, sendo a primeira menos indicada e a última mais indicada:

1) Você pode dispor seu layout de maneira diferente: colocando primeiro seu ScrollView e depois sua Toolbar por exemplo,

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

    <ScrollView .../>

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

</RelativeLayout>

2) Você pode manter seu layout do jeito que está e definir como seus componentes irão se comportar, ou seja, setando os atributos que irão definir como seus componentes vão se posicionar dentro do seu RelativeLayout: definindo o atributo android:layout_below="" no seu ScrollView, dizendo para ele se posicionar abaixo de outro layout (id), por exemplo,

<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) Você pode substituir seu RelativeLayout para um LinearLayout com a orientação vertical. Isso fará com que seu layout seja construido de forma linear e respeitando a ordem. Atribuindo o atributo android:layout_weight="1", você irá garantir que sua ScrollView irá ocupar todo o tamanho que ela irá precisar:

<?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>
1
  • 1
    Muito bom cara! Valeu mesmo por sua explicação! Usei a segunda opção, foi mais apropriada para meu caso! Muito obrigado!!!! 16/01/2016 às 2:15

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .