Scroolview passing the Toolbar

Asked

Viewed 100 times

0

I’m trying to create a registration screen with a Scroll, with a Scroll. However Scroll is overwriting the Toolbar.

I tried to put the attribute app:layout_behavior="@string/appbar_scrolling_view_behavior" but it didn’t work.

Someone’s been through it ?

Scroll passando o toolbar

Code:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.artur.decorusfinale.Venda">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <include layout="@layout/toolbar" />

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

    <ScrollView

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

        <RelativeLayout
            android:id="@+id/activity_main"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin">

            <ImageView

                android:id="@+id/iv_profile"
                android:layout_width="140dp"
                android:layout_height="140dp"
                android:layout_marginTop="10dp"
                android:contentDescription="Image de perfil"
                app:srcCompat="@drawable/cliente_cadastrado" />

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginStart="10dp"
                android:layout_marginTop="10dp"
                android:layout_toEndOf="@+id/iv_profile"
                android:layout_toRightOf="@+id/iv_profile">

                <EditText
                    android:id="@+id/et_email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:ems="10"
                    android:hint="*Email"
                    android:inputType="textEmailAddress" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/til_email"
                android:layout_marginLeft="10dp"
                android:layout_marginStart="10dp"
                android:layout_marginTop="10dp"
                android:layout_toEndOf="@+id/iv_profile"
                android:layout_toRightOf="@+id/iv_profile">

                <EditText
                    android:id="@+id/et_password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:ems="10"
                    android:hint="*Senha"
                    android:inputType="textPassword" />
            </android.support.design.widget.TextInputLayout>

            <TextView
                android:id="@+id/sub_title_2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/iv_profile"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="40dp"
                android:background="#005740"
                android:gravity="center"
                android:padding="6dp"
                android:text="Endereço"
                android:textColor="#f9f9f9"
                android:textSize="20sp" />

            <LinearLayout
                android:id="@+id/ll_fieldset_1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/sub_title_2"
                android:layout_marginTop="10dp"
                android:orientation="horizontal">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_zip_code"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">

                    <EditText
                        android:id="@+id/et_zip_code"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:ems="10"
                        android:hint="*CEP"
                        android:inputType="number"
                        android:maxLength="8" />
                </android.support.design.widget.TextInputLayout>

                <TextView
                    android:id="@+id/tv_zip_code_search"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:onClick="searchZipCode"
                    android:paddingTop="15dp"
                    android:text="Esqueci o CEP"
                    android:textColor="#f9f9f9"
                    android:textSize="18sp" />
            </LinearLayout>


            <LinearLayout
                android:id="@+id/ll_fieldset_2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/ll_fieldset_1"
                android:layout_marginTop="10dp"
                android:orientation="horizontal">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_street"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">

                    <EditText
                        android:id="@+id/et_street"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:ems="10"
                        android:hint="*Rua"
                        android:inputType="text" />
                </android.support.design.widget.TextInputLayout>

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_complement"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">

                    <EditText
                        android:id="@+id/et_complement"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:ems="10"
                        android:hint="*Complemento"
                        android:inputType="text"
                        android:maxLength="8" />
                </android.support.design.widget.TextInputLayout>
            </LinearLayout>


            <LinearLayout
                android:id="@+id/ll_fieldset_3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/ll_fieldset_2"
                android:layout_marginTop="10dp"
                android:orientation="horizontal">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_number"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">

                    <EditText
                        android:id="@+id/et_number"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:ems="10"
                        android:hint="*Nº"
                        android:inputType="number" />
                </android.support.design.widget.TextInputLayout>

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_neighbor"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">

                    <EditText
                        android:id="@+id/et_neighbor"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:ems="10"
                        android:hint="*Bairro"
                        android:inputType="text" />
                </android.support.design.widget.TextInputLayout>
            </LinearLayout>


            <LinearLayout
                android:id="@+id/ll_fieldset_4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@+id/ll_fieldset_3"
                android:layout_marginTop="10dp"
                android:orientation="horizontal">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_city"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">

                    <EditText
                        android:id="@+id/et_city"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:ems="10"
                        android:hint="*Cidade"
                        android:inputType="text" />
                </android.support.design.widget.TextInputLayout>

                <Spinner
                    android:id="@+id/sp_state"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1" />
            </LinearLayout>


            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_below="@+id/ll_fieldset_4"
                android:layout_marginTop="60dp"
                android:background="#cc2a00"
                android:gravity="center"
                android:text="Enviar cadastro"
                android:textColor="#ffffff"
                android:textSize="20sp" />

        </RelativeLayout>
    </ScrollView>
</RelativeLayout>

2 answers

2


Insert a id in his AppBarLayout. Behold:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"        
    android:theme="@style/AppTheme.AppBarOverlay">

    <include layout="@layout/toolbar_teste" />

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

Then just position your ScrollView below the AppBarLayout using layout_below. Behold:

<ScrollView
    android:layout_below="@id/appbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"        
    .
    .
    .

2

The right way to use it is to use a Coordinatorlayout instead of a Relativelayout

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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <include layout="@layout/toolbar" />

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

    <include layout="@layout/content_com_relative" />

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

Put all your registration content inside this new layout to be separate and work better! Don’t forget to put app:layout_behavior="@string/appbar_scrolling_view_behavior" within the first Tag which in your case would be the Relativelayout.

I hope it helps anything we’re there!

Browser other questions tagged

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