How to leave a fixed footer in the Android layout?

-1

I have the following layout in xml in my Android designer:

<?xmlversion="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Ativar Notificações:" />

            <CheckBox
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Inativo"
                android:id="@+id/checkAtivarNotificacao" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tempo em Minutos das Notificações:"
                android:layout_marginTop="10dp" />

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="none|number"
                android:ems="10"
                android:id="@+id/txtIntervaloNotificacao"
                android:maxLength="4"
                android:focusable="true"
                android:focusableInTouchMode="true"/>
        </LinearLayout>

    </ScrollView>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom|center_horizontal">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Salvar"
        android:id="@+id/btSalvarConfiguracao" />

</LinearLayout>

The problem is that according to what I'm adding components on the screen and ScrollView goes down the save button disappears, so I want to leave a footer space with the save button fixed and flexible layout content regardless of how much it grows, just like in the standard android messaging application illustrated below:

    
asked by anonymous 16.12.2016 / 13:07

1 answer

0

It would be interesting to put your xml , so we know where to go wrong. But as the question is generic, here is my answer:

Use RelativeLayout . Whatever you want to center within it you use some of its centralization property:

  • centerInParent - Centers in the middle (horizontally and vertically) of RelativeLayout .
  • centerHorizontal - Centers horizontally, relative to RelativeLayout
  • centerVertical - Centralizes vertically, in relation to RelativeLayout
  • Code sample:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
        <Button
            android:id="@+id/btn"
            android:layout_height="wrap_content"
            android:layout_width="100dp"
            android:layout_centerInParent="true"/>
    
    </RelativeLayout>
    

    // EDIT

    With your best specification in the question, I repeat, putting together an android layout each has its own way, and they have several ways of doing the same thing.

    In your case I would simply put all that code inside a LinearLayout and assign the layout_weight=1 property to ScrollView .

    Follow the code below:

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Ativar Notificações:" />
    
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Inativo"
                    android:id="@+id/checkAtivarNotificacao" />
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Tempo em Minutos das Notificações:"
                    android:layout_marginTop="10dp" />
    
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:inputType="none|number"
                    android:ems="10"
                    android:id="@+id/txtIntervaloNotificacao"
                    android:maxLength="4"
                    android:focusable="true"
                    android:focusableInTouchMode="true"/>
            </LinearLayout>
    
        </ScrollView>
    
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Salvar"
                android:id="@+id/btSalvarConfiguracao"/>
        </LinearLayout>
    </LinearLayout>
    
        
    16.12.2016 / 13:18