Keyboard does not override button in Relative Layout

Asked

Viewed 292 times

1

Good morning, everyone. I have a problem in my application: I have a screen to register devices, as image below, however, when enabling a field for typing, the keyboard does not override the button:

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

What left me with more doubt, is that I have another layout in which this does not occur:

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

Both buttons have the same encoding:

BUTTON SAVE DEVICE

<Button
    android:id="@+id/btn_gravaDisp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginLeft="20dp"
    android:text="Gravar Dispositivo"
    android:background="@color/colorPrimaryDark"
    android:textColor="@android:color/white"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>

USER SAVE BUTTON

<Button
    android:id="@+id/btn_gravaUser"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginLeft="20dp"
    android:text="Gravar Usuário"
    android:background="@color/colorPrimaryDark"
    android:textColor="@android:color/white"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>

I checked in some other posts that there is an option of adjustPan, however, both these classes extend Fragment, not to the Appcompatactivity.

Below, java code of both classes:

Register Device:

public class CadastrarDispositivos extends Fragment {


@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    getActivity().setTitle("Cadastro de Dispositivos");
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup 
container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.cadastrodispositivos, container, 
false);
}

}

Users:

public class Usuarios extends Fragment {


@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    getActivity().setTitle("Usuários");
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup 
container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.usuarios, container, false);
}

}

Xml of device registration:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.TextInputLayout
    android:id="@+id/inputNomeDisp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="20dp">
    <android.support.design.widget.TextInputEditText
        android:id="@+id/editNomeDisp"
        android:hint="Nome do dispositivo"
        android:textColorHint="@color/colorPrimaryDark"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:maxLength="20"
        android:inputType="text"/>
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:layout_below="@id/inputNomeDisp"
    android:id="@+id/inputTipoDisp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.design.widget.TextInputEditText
        android:id="@+id/editTipoDisp"
        android:layout_width="match_parent"
        android:hint="Tipo do dispositivo"
        android:textColorHint="@color/colorPrimaryDark"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:maxLength="20"
        android:inputType="text"/>
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:layout_below="@id/inputTipoDisp"
    android:id="@+id/inputLocalDisp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.design.widget.TextInputEditText
        android:id="@+id/editLocalDisp"
        android:layout_width="match_parent"
        android:hint="Local do dispositivo"
        android:textColorHint="@color/colorPrimaryDark"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:maxLength="20"
        android:inputType="text"/>
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:layout_below="@id/inputLocalDisp"
    android:id="@+id/inputPortaDisp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.design.widget.TextInputEditText
        android:id="@+id/editPortaDisp"
        android:layout_width="match_parent"
        android:hint="Porta do dispositivo"
        android:textColorHint="@color/colorPrimaryDark"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        android:maxLength="20"
        android:inputType="number"/>
</android.support.design.widget.TextInputLayout>

<Button
    android:id="@+id/btn_gravaDisp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginLeft="20dp"
    android:text="Gravar Dispositivo"
    android:background="@color/colorPrimaryDark"
    android:textColor="@android:color/white"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/ 
</RelativeLayout>

Xml of user registration:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.TextInputLayout
android:id="@+id/inputNomeUsuario"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp">
    <android.support.design.widget.TextInputEditText
        android:id="@+id/editNomeUsuario"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:hint="Nome do usuario"
        android:textColorHint="@color/colorPrimaryDark"/>
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:id="@+id/inputSenhaUsuario"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/inputNomeUsuario">
    <android.support.design.widget.TextInputEditText
        android:id="@+id/editSenhaUsuario"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:hint="Senha do usuario"
        android:textColorHint="@color/colorPrimaryDark"/>
</android.support.design.widget.TextInputLayout>

<android.support.v7.widget.AppCompatTextView
    android:layout_below="@id/inputSenhaUsuario"
    android:id="@+id/txtAdministrador"
    android:layout_margin="20dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Administrador?"
    android:textSize="20dp"
    android:textColor="@color/colorPrimaryDark"/>

<android.support.v7.widget.AppCompatCheckBox
    android:id="@+id/cbx_Sim"
    android:text="Sim"
    android:textSize="20dp"
    android:textColor="@color/colorPrimaryDark"
    android:layout_below="@id/txtAdministrador"
    android:layout_marginLeft="20dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<android.support.v7.widget.AppCompatCheckBox
    android:id="@+id/cbx_Nao"
    android:text="Não"
    android:textSize="20dp"
    android:textColor="@color/colorPrimaryDark"
    android:layout_below="@id/cbx_Sim"
    android:layout_marginLeft="20dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/btn_gravaUser"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="20dp"
    android:layout_marginRight="20dp"
    android:layout_marginLeft="20dp"
    android:text="Gravar Usuário"
    android:background="@color/colorPrimaryDark"
    android:textColor="@android:color/white"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>

</RelativeLayout>

From now on I thank anyone who can help me!

Thanks!

1 answer

1

It seems that what is causing the button not to be overwritten is the item layout_alignParentBottom="true". What it does is to literally align the view (in this case the button) with the end of the Layout, so that when the keyboard appears, the button will "go up" along with the end of the Layout instead of being overlaid.

One of the two buttons is being overridden because this option is being ignored. Try changing the two to "false" and swap one by one to see the results.

  • It remained the same. I changed both to "false" and both went to the top of the screen. 1 - I changed users, and it worked normal, as prints 2 - I changed devices registration, continued with the error above.

  • Check attribute inheritances. It may be that they are different and overlapping what is in XML. Also check that nothing is being programmatically changed.

Browser other questions tagged

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