I have 3 forms in EditText and I need to readjust the position automatically when the user click in form and keyboard appear, in my manifest.xml I added this line: " android:windowSoftInputMode="stateHidden|adjustResize" "
This is my XML Code of The screen:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="@drawable/bg_farm"
>
<Button
android:id="@+id/buttonLogar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="136dp"
android:background="@drawable/bgbuttonform"
android:drawableRight="@drawable/ic_check_black_24dp"
android:outlineAmbientShadowColor="@android:color/black"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="@string/confirmar_dados"
android:textColor="@android:color/white"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextPassword" />
<Button
android:id="@+id/btn_selecionar_foto"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="100dp"
android:background="@drawable/bg_btn_rounded_img"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:text="Selecione uma foto"
android:textColor="@android:color/white"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editTextEmailUser"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="32dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="15dp"
android:background="@drawable/bg_editextrounded"
android:ems="10"
android:hint=" Digite aqui seu email"
android:inputType="textEmailAddress"
android:paddingLeft="10dp"
app:layout_constraintBottom_toTopOf="@+id/editTextPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextUser" />
<EditText
android:id="@+id/editTextUser"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="32dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="15dp"
android:background="@drawable/bg_editextrounded"
android:ems="10"
android:hint="Digite aqui seu nome"
android:inputType="textPersonName"
android:paddingLeft="10dp"
app:layout_constraintBottom_toTopOf="@+id/editTextEmailUser"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_selecionar_foto" />
<EditText
android:id="@+id/editTextPassword"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="32dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="8dp"
android:background="@drawable/bg_editextrounded"
android:ems="10"
android:hint="Digite aqui sua senha"
android:inputType="textPassword"
android:paddingLeft="8dp"
app:layout_constraintBottom_toTopOf="@+id/buttonLogar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextEmailUser" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageFotoUser"
android:layout_width="150dp"
android:layout_height="150dp"
app:civ_border_width="1dp"
app:civ_border_color="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="@+id/btn_selecionar_foto"
app:layout_constraintEnd_toEndOf="@+id/btn_selecionar_foto"
app:layout_constraintStart_toStartOf="@+id/btn_selecionar_foto"
app:layout_constraintTop_toTopOf="@+id/btn_selecionar_foto"
/>
<TextView
android:id="@+id/textViewInicial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="175dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="178dp"
android:layout_marginBottom="33dp"
android:text="Seja bem vindo(a) ao Agro Lucros!\nPreencha o formulário abaixo para seguir"
android:typeface="serif"
android:textSize="18.5dp"
android:textColor="@android:color/black"
android:gravity="center"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/btn_selecionar_foto"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textJaTemConta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="94dp"
android:text="Já possui uma conta? Clique aqui!"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/white"
android:fontFamily="sans-serif-black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/buttonLogar" />
</androidx.constraintlayout.widget.ConstraintLayout>
I need basically when keyboard appear the edit text scrolling to up screen, sorry for my explanation.
Just adding to what @dmak2709 has advised above.
I'd suggest you to use NestedScrollView
for all your layout like below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/buttonLogar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="136dp"
android:background="@drawable/bgbuttonform"
android:drawableRight="@drawable/ic_check_black_24dp"
android:outlineAmbientShadowColor="@android:color/black"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="@string/confirmar_dados"
android:textColor="@android:color/white"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextPassword" />
<Button
android:id="@+id/btn_selecionar_foto"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="100dp"
android:background="@drawable/bg_btn_rounded_img"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:text="Selecione uma foto"
android:textColor="@android:color/white"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editTextEmailUser"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="32dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="15dp"
android:background="@drawable/bg_editextrounded"
android:ems="10"
android:hint=" Digite aqui seu email"
android:inputType="textEmailAddress"
android:paddingLeft="10dp"
app:layout_constraintBottom_toTopOf="@+id/editTextPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextUser" />
<EditText
android:id="@+id/editTextUser"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="32dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="15dp"
android:background="@drawable/bg_editextrounded"
android:ems="10"
android:hint="Digite aqui seu nome"
android:inputType="textPersonName"
android:paddingLeft="10dp"
app:layout_constraintBottom_toTopOf="@+id/editTextEmailUser"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn_selecionar_foto" />
<EditText
android:id="@+id/editTextPassword"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="32dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="8dp"
android:background="@drawable/bg_editextrounded"
android:ems="10"
android:hint="Digite aqui sua senha"
android:inputType="textPassword"
android:paddingLeft="8dp"
app:layout_constraintBottom_toTopOf="@+id/buttonLogar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextEmailUser" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageFotoUser"
android:layout_width="150dp"
android:layout_height="150dp"
app:civ_border_width="1dp"
app:civ_border_color="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="@+id/btn_selecionar_foto"
app:layout_constraintEnd_toEndOf="@+id/btn_selecionar_foto"
app:layout_constraintStart_toStartOf="@+id/btn_selecionar_foto"
app:layout_constraintTop_toTopOf="@+id/btn_selecionar_foto"
/>
<TextView
android:id="@+id/textViewInicial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="175dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="178dp"
android:layout_marginBottom="33dp"
android:text="Seja bem vindo(a) ao Agro Lucros!\nPreencha o formulário abaixo para seguir"
android:typeface="serif"
android:textSize="18.5dp"
android:textColor="@android:color/black"
android:gravity="center"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/btn_selecionar_foto"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textJaTemConta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="94dp"
android:text="Já possui uma conta? Clique aqui!"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@android:color/white"
android:fontFamily="sans-serif-black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/buttonLogar" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Check out this page if you want more information on this.
Hope that helps.