Android layout doesn´t resize when keyboard shows - android

as title says, i have a problem resizing my layout when keyboard appears, I did the same in new project and it works, nope in this project:
I have added "android:windowSoftInputMode="adjustResize" in my activity manifest file
This is my .xml file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/contentRegister1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true">
<include
android:id="#+id/customActionBar"
layout="#layout/action_bar_text"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/customActionBar">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvInfoRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="25dp"
android:layout_marginEnd="30dp"
android:text="#string/register_header_text"
android:textAlignment="center"
android:textColor="#ff999999"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/nifRegisterBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="22dp"
android:layout_marginEnd="30dp"
android:textColorHint="#android:color/black"
app:boxStrokeColor="#android:color/black"
app:errorEnabled="true"
app:hintTextAppearance="#style/TextFormStyle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvInfoRegister">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/nifRegisterValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/nif_nie"
android:inputType="textCapCharacters"
android:maxLength="9"
android:maxLines="1"
android:textColor="#000000"
android:textSize="15sp" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/ivOkNifRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_tick"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/nifRegisterBox"
app:layout_constraintEnd_toEndOf="#id/nifRegisterBox"
app:layout_constraintTop_toTopOf="#id/nifRegisterBox"
app:layout_constraintVertical_bias="0.39" />
<ImageView
android:id="#+id/ivWrongNifRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_error"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/nifRegisterBox"
app:layout_constraintEnd_toEndOf="#id/nifRegisterBox"
app:layout_constraintTop_toTopOf="#id/nifRegisterBox"
app:layout_constraintVertical_bias="0.39" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/birthRegisterBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="30dp"
android:textColorHint="#android:color/black"
app:boxStrokeColor="#android:color/black"
app:errorEnabled="true"
app:hintTextAppearance="#style/TextFormStyle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/nifRegisterBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/birthRegisterValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="false"
android:hint="#string/register_birthdate_label"
android:inputType="date"
android:maxLines="1"
android:singleLine="true"
android:textColor="#000000"
android:textSize="15sp" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/ivOkBirthRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_tick"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/birthRegisterBox"
app:layout_constraintEnd_toEndOf="#id/birthRegisterBox"
app:layout_constraintTop_toTopOf="#id/birthRegisterBox"
app:layout_constraintVertical_bias="0.39" />
<ImageView
android:id="#+id/ivWrongBirthRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_error"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/birthRegisterBox"
app:layout_constraintEnd_toEndOf="#id/birthRegisterBox"
app:layout_constraintTop_toTopOf="#id/birthRegisterBox"
app:layout_constraintVertical_bias="0.39" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/mailRegisterBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="30dp"
android:textColorHint="#android:color/black"
app:boxStrokeColor="#android:color/black"
app:errorEnabled="true"
app:hintTextAppearance="#style/TextFormStyle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/birthRegisterBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/mailRegisterValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/register_email_label"
android:inputType="textEmailAddress"
android:maxLines="1"
android:textColor="#000000"
android:textSize="15sp" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/ivOkMailRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_tick"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/mailRegisterBox"
app:layout_constraintEnd_toEndOf="#id/mailRegisterBox"
app:layout_constraintTop_toTopOf="#id/mailRegisterBox"
app:layout_constraintVertical_bias="0.39" />
<ImageView
android:id="#+id/ivWrongMailRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_error"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/mailRegisterBox"
app:layout_constraintEnd_toEndOf="#id/mailRegisterBox"
app:layout_constraintTop_toTopOf="#id/mailRegisterBox"
app:layout_constraintVertical_bias="0.39" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/remailRegisterBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="30dp"
android:textColorHint="#android:color/black"
app:boxStrokeColor="#android:color/black"
app:errorEnabled="true"
app:hintTextAppearance="#style/TextFormStyle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/mailRegisterBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/remailRegisterValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/register_email_confirm_label"
android:inputType="textEmailAddress"
android:maxLines="1"
android:textColor="#000000"
android:textSize="15sp" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/ivOkReMailRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_tick"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/remailRegisterBox"
app:layout_constraintEnd_toEndOf="#id/remailRegisterBox"
app:layout_constraintTop_toTopOf="#id/remailRegisterBox"
app:layout_constraintVertical_bias="0.39" />
<ImageView
android:id="#+id/ivWrongReMailRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_error"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/remailRegisterBox"
app:layout_constraintEnd_toEndOf="#id/remailRegisterBox"
app:layout_constraintTop_toTopOf="#id/remailRegisterBox"
app:layout_constraintVertical_bias="0.39" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/mobileRegisterBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="30dp"
android:textColorHint="#android:color/black"
app:boxStrokeColor="#android:color/black"
app:errorEnabled="true"
app:hintTextAppearance="#style/TextFormStyle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/remailRegisterBox">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/mobileRegisterValue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/register_mobile_phone_label"
android:inputType="number"
android:maxLength="9"
android:maxLines="1"
android:textColor="#000000"
android:textSize="15sp" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/ivOkMobileRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_tick"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/mobileRegisterBox"
app:layout_constraintEnd_toEndOf="#id/mobileRegisterBox"
app:layout_constraintTop_toTopOf="#id/mobileRegisterBox"
app:layout_constraintVertical_bias="0.39" />
<ImageView
android:id="#+id/ivWrongMobileRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_error"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="#id/mobileRegisterBox"
app:layout_constraintEnd_toEndOf="#id/mobileRegisterBox"
app:layout_constraintTop_toTopOf="#id/mobileRegisterBox"
app:layout_constraintVertical_bias="0.39" />
<LinearLayout
android:id="#+id/check_box_and_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="30dp"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/mobileRegisterBox">
<CheckBox
android:id="#+id/legales"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="9dp"
android:button="#drawable/checkbox_selector" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:text="#string/register_legales_label"
android:textSize="13sp" />
<TextView
android:id="#+id/termsOfAgreement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/register_legales_label_hiperlink"
android:textColor="#ffd87920"
android:textSize="13sp" />
</LinearLayout>
<TextView
android:id="#+id/tvErrorLegal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:text="#string/condiciones_legales_error"
android:textColor="#ff0000"
android:textSize="12sp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/check_box_and_text" />
<Button
android:id="#+id/btNextRegister1"
style="#style/LoginButtonEntrarStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="27dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="32dp"
android:background="#drawable/button_main_card_dashboard"
android:text="#string/request_reset_password_init_button_next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvErrorLegal" />
</androidx.constraintlayout.widget.ConstraintLayout>
And this is the include file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#drawable/dashboard_title_bg">
<TextView
android:id="#+id/actionBarCentralTextView"
style="#style/MainTitleActionBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.6" />
<ImageButton
android:id="#+id/btActionBarMenuText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:background="?android:selectableItemBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.6" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/back_container_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.6">
<ImageButton
android:id="#+id/btActionBarNotificationsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:background="?android:selectableItemBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/tvSecondTitleText"
style="#style/SecondaryTitleActionBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Anyone knows why it is not resizing?
Thanks,

By it's standard documentation:
Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows.
I think your problem would be solved by adding android:fitsSystemWindows=true to your root view.

Related

Center the ConstraintLayout in the screen

I'm trying to vertically center a ConstraintLayout in the screen. The ConstraintLayout is the root element of the entire layout of the LoginActivity.
I set the android:layout_gravity to center (as in the code below). It does the job in the Android Studio Design Editor, but when I run the app on the phone the ConstraintLayout is aligned to the top of the screen.
How can I effectively center the ConstraintLayout in the screen? Thanks.
<?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="wrap_content"
android:layout_gravity="center"
tools:context=".activities.LoginActivity">
<ImageView
android:id="#+id/ivLogo"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginTop="50dp"
android:contentDescription="#string/cutitapp_logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_cutitapp_logo"
tools:srcCompat="#drawable/ic_cutitapp_logo" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilEmail"
style="#style/CutitApp.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="52dp"
android:layout_marginEnd="24dp"
app:endIconMode="clear_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/ivLogo">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:hint="#string/email"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilPassword"
style="#style/CutitApp.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tilEmail"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:hint="#string/password"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/etEmail"
tools:ignore="TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="#+id/tvError"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="16dp"
android:textColor="?attr/colorError"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tilPassword" />
<Button
android:id="#+id/btnLogin"
style="#style/CutitApp.Button"
android:layout_width="0dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:text="#string/login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvError" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/btnLogin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/not_a_member" />
<Button
android:id="#+id/btnRegister"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/register"
android:textAllCaps="false"
android:textColor="#color/design_default_color_primary"
android:textSize="14sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Here you go.
I just added an extra ConstraintLayout
<?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="wrap_content"
android:layout_gravity="center">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<ImageView
android:id="#+id/ivLogo"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginTop="50dp"
android:contentDescription="#string/cutitapp_logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_cutitapp_logo"
tools:srcCompat="#drawable/ic_cutitapp_logo" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilEmail"
style="#style/CutitApp.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="52dp"
android:layout_marginEnd="24dp"
app:endIconMode="clear_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/ivLogo">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:hint="#string/email"
android:inputType="textEmailAddress"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilPassword"
style="#style/CutitApp.TextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tilEmail"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:hint="#string/password"
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/etEmail"
tools:ignore="TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="#+id/tvError"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="16dp"
android:textColor="?attr/colorError"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tilPassword" />
<Button
android:id="#+id/btnLogin"
style="#style/CutitApp.Button"
android:layout_width="0dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:text="#string/login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvError" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/btnLogin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/not_a_member" />
<Button
android:id="#+id/btnRegister"
style="#style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/register"
android:textAllCaps="false"
android:textColor="#color/design_default_color_primary"
android:textSize="14sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Why does the height of my Constraintlayout increase when I place it in a Scrollview?

I have a ConstraintLayout which shows all items on my smartphone without the need to scroll. Nevertheless I want to surround the ConstraintLayout with a ScrollView that a user with smaller phones can scroll.
When adding the ScrollView, even on my smartphone I need to scroll to reach the last to buttons. The height of the ConstraintLayout increases and the two buttons with id="#+id/button3" and id="#+id/button4" appear after a big empty area.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<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:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/button3"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="16dp"
android:drawableLeft="#drawable/ic_chevron_left_black_24dp"
android:onClick="zurueckZuMainActivity"
android:text="Zurück"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/button4"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="16dp"
android:drawableRight="#drawable/ic_chevron_right_black_24dp"
android:onClick="weiter"
android:text="Weiter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Bestellformular"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:text="Schritt 1/4: Lieferadresse"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView6" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="10dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="10dp"
app:layout_constraintBottom_toBottomOf="#+id/textInputLayout_vorname"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_vorname"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/textInputLayout_vorname"
app:layout_constraintVertical_bias="0.523"
app:srcCompat="#drawable/ic_person_black_24dp" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_vorname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView9"
app:layout_constraintTop_toBottomOf="#+id/textView7"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/vorname_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Vorname"
android:inputType="textCapWords"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_nachname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/textInputLayout_vorname"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_vorname">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Nachname"
android:inputType="textCapWords"
android:id="#+id/nachname_edit"
/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/imageView11"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toTopOf="#+id/textInputLayout_strasse"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_telefonnummer"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView9"
app:layout_constraintVertical_bias="0.587"
app:srcCompat="#drawable/ic_phone_black_24dp" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_telefonnummer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView11"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_nachname">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Telefonnummer"
android:id="#+id/telefonnummer_edit"
android:inputType="number"
/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/imageView12"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="10dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="4dp"
app:layout_constraintBottom_toBottomOf="#+id/textInputLayout_email"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_email"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_telefonnummer"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="#drawable/ic_email_black_24dp" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_email"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView12"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_telefonnummer">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="E-Mail-Adresse"
android:id="#+id/email_edit"
/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/imageView13"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="10dp"
android:layout_marginTop="300dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="248dp"
app:layout_constraintBottom_toTopOf="#+id/button3"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_strasse"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_vorname"
app:layout_constraintVertical_bias="0.361"
app:srcCompat="#drawable/ic_location_on_black_24dp" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_strasse"
android:layout_width="0dp"
android:layout_height="53dp"
android:layout_marginTop="36dp"
android:layout_marginEnd="7dp"
android:layout_marginBottom="23dp"
app:layout_constraintBottom_toTopOf="#+id/textInputLayout_stadt"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_nummer"
app:layout_constraintStart_toEndOf="#+id/imageView13"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_email"
app:layout_constraintVertical_bias="0.13">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Straße"
android:inputType="textCapWords"
android:id="#+id/strasse_edit"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_nummer"
android:layout_width="152dp"
android:layout_height="53dp"
android:layout_marginTop="34dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textInputLayout_strasse"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_email">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/nummer_edit"
android:layout_width="163dp"
android:layout_height="wrap_content"
android:hint="Nummer"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_plz"
android:layout_width="108dp"
android:layout_height="56dp"
android:layout_marginStart="55dp"
android:layout_marginTop="7dp"
android:layout_marginEnd="12dp"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_stadt"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_strasse">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="106dp"
android:layout_height="44dp"
android:hint="PLZ"
android:id="#+id/plz_edit"
android:inputType="number"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_stadt"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginTop="7dp"
android:layout_marginEnd="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textInputLayout_plz"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_nummer"
app:layout_constraintVertical_bias="0.0">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Stadt"
android:id="#+id/stadt_edit"
android:inputType="textCapWords"
/>
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="1dp"
android:text="Füllen Sie bitte alle nachfolgenden Felder aus! "
app:layout_constraintBottom_toTopOf="#+id/textInputLayout_vorname"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView7" />
</androidx.constraintlayout.widget.ConstraintLayout>
How can I solve this?
yu have used fillviewport="true" which basically increases the height of your scroll view to use remaining space if there is extra space available in viewport. If you will make it false, the height of the viewport will be as you expected.
Try wrapping your Buttons in their own ConstraintLayout, inside linearLayout3
<androidx.constraintlayout.widget.ConstraintLayout
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="0dp">
<Button
android:id="#+id/button4"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="16dp"
android:onClick="weiter"
android:text="Weiter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/button3"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="16dp"
android:onClick="zurueckZuMainActivity"
android:text="Zurück"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
You could try to add a RelativeLayout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Bestellformular"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:text="Schritt 1/4: Lieferadresse"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView6" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="10dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="10dp"
app:layout_constraintBottom_toBottomOf="#+id/textInputLayout_vorname"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_vorname"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/textInputLayout_vorname"
app:layout_constraintVertical_bias="0.523"
/>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_vorname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView9"
app:layout_constraintTop_toBottomOf="#+id/textView7"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/vorname_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Vorname"
android:inputType="textCapWords"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_nachname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/textInputLayout_vorname"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_vorname">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Nachname"
android:inputType="textCapWords"
android:id="#+id/nachname_edit"
/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/imageView11"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toTopOf="#+id/textInputLayout_strasse"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_telefonnummer"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView9"
app:layout_constraintVertical_bias="0.587"
/>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_telefonnummer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView11"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_nachname">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Telefonnummer"
android:id="#+id/telefonnummer_edit"
android:inputType="number"
/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/imageView12"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="10dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="4dp"
app:layout_constraintBottom_toBottomOf="#+id/textInputLayout_email"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_email"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_telefonnummer"
app:layout_constraintVertical_bias="1.0"
/>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_email"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView12"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_telefonnummer">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="E-Mail-Adresse"
android:id="#+id/email_edit"
/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="#+id/imageView13"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginStart="10dp"
android:layout_marginTop="300dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="248dp"
app:layout_constraintBottom_toTopOf="#+id/button3"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_strasse"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_vorname"
app:layout_constraintVertical_bias="0.361"
/>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_strasse"
android:layout_width="0dp"
android:layout_height="53dp"
android:layout_marginTop="36dp"
android:layout_marginEnd="7dp"
android:layout_marginBottom="23dp"
app:layout_constraintBottom_toTopOf="#+id/textInputLayout_stadt"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_nummer"
app:layout_constraintStart_toEndOf="#+id/imageView13"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_email"
app:layout_constraintVertical_bias="0.13">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Straße"
android:inputType="textCapWords"
android:id="#+id/strasse_edit"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_nummer"
android:layout_width="152dp"
android:layout_height="53dp"
android:layout_marginTop="34dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textInputLayout_strasse"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_email">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/nummer_edit"
android:layout_width="163dp"
android:layout_height="wrap_content"
android:hint="Nummer"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_plz"
android:layout_width="108dp"
android:layout_height="56dp"
android:layout_marginStart="55dp"
android:layout_marginTop="7dp"
android:layout_marginEnd="12dp"
app:layout_constraintEnd_toStartOf="#+id/textInputLayout_stadt"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_strasse">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="106dp"
android:layout_height="44dp"
android:hint="PLZ"
android:id="#+id/plz_edit"
android:inputType="number"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout_stadt"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginTop="7dp"
android:layout_marginEnd="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textInputLayout_plz"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout_nummer"
app:layout_constraintVertical_bias="0.0">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Stadt"
android:id="#+id/stadt_edit"
android:inputType="textCapWords"
/>
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="1dp"
android:text="Füllen Sie bitte alle nachfolgenden Felder aus! "
app:layout_constraintBottom_toTopOf="#+id/textInputLayout_vorname"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView7" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="#+id/button3"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="16dp"
android:onClick="zurueckZuMainActivity"
android:text="Zurück"
android:layout_alignParentBottom="true"/>
<Button
android:id="#+id/button4"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="16dp"
android:onClick="weiter"
android:text="Weiter"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
You have used fillviewport="true" which basically increases the height of your scroll view to use remaining space if there is extra space available in viewport. If you will make it false, or just remove that attribute, the height of the constraint layout will be as you expected. By default, the value of fillviewport is false.

Move one particular view up when opening a keyboard not the entire layout

I want functionality like Facebook like when we create any post with an image on it only they push one bar on top of the image, not the entire layout. In my case, I am using NestedScrollView as a parent with child ConstraintLayout and the bar is designed in Linear layout.
This is my app:
I want something like this:
This is my XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.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"
android:background="#color/white"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.03" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.97" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/select_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#dimen/dimen_15dp"
android:clickable="true"
android:clipChildren="false"
android:focusable="true"
android:foreground="#drawable/ripple"
android:paddingTop="#dimen/dimen_5dp"
android:paddingEnd="#dimen/dimen_5dp"
android:paddingBottom="#dimen/dimen_5dp"
android:src="#drawable/left_arrow"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.00"
app:layout_constraintStart_toStartOf="#id/guideline1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.00" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/back_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginTop="#dimen/dimen_15dp"
android:clickable="true"
android:focusable="true"
android:fontFamily="#font/opensans_bold"
android:paddingTop="#dimen/dimen_5dp"
android:paddingEnd="#dimen/dimen_5dp"
android:paddingBottom="#dimen/dimen_5dp"
android:text="#string/new_post"
android:textColor="#color/colorPrimaryDark"
android:textSize="#dimen/dimen_16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/select_back"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.00" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/postTextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#dimen/dimen_15dp"
android:clickable="true"
android:focusable="true"
android:fontFamily="#font/roboto_regular"
android:foreground="?android:selectableItemBackground"
android:paddingStart="#dimen/dimen_5dp"
android:paddingTop="#dimen/dimen_5dp"
android:paddingBottom="#dimen/dimen_5dp"
android:text="#string/post"
android:textColor="#color/colorPrimaryDark"
android:textSize="#dimen/dimen_16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline2"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/back_title"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.00" />
<View
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="12dp"
android:background="#color/grey_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/select_back"
app:layout_constraintVertical_bias="0.0" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:src="#drawable/rock"
app:civ_border_color="#color/white"
app:civ_border_width="2dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/line" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/dimen_10dp"
android:layout_marginTop="20dp"
android:clickable="true"
android:focusable="true"
android:fontFamily="#font/opensans_bold"
android:text="Dwayne johnson"
android:textColor="#color/textview_black"
android:textSize="#dimen/dimen_14sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/profile_image"
app:layout_constraintTop_toBottomOf="#+id/line" />
<com.skyfishjy.library.RippleBackground
android:id="#+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="44dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/line"
app:rb_color="#29B6F6"
app:rb_duration="2000"
app:rb_radius="5dp"
app:rb_rippleAmount="3"
app:rb_scale="4">
<ImageView
android:id="#+id/world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="TODO"
android:padding="10dp"
android:src="#drawable/world" />
</com.skyfishjy.library.RippleBackground>
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/down_arrow"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginTop="16dp"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
android:src="#drawable/ic_arrow_down_sign_to_navigate"
app:layout_constraintStart_toEndOf="#+id/content"
app:layout_constraintTop_toBottomOf="#+id/line" />
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_below="#+id/rel"
android:layout_marginTop="8dp"
android:background="#DCDCDC"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/profile_image" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/category1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:background="#drawable/button_background"
android:clickable="true"
android:focusable="true"
android:fontFamily="sans-serif"
android:foreground="?android:selectableItemBackground"
android:padding="5dp"
android:text="#string/personal"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="10sp"
android:textStyle="normal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/view"
app:textAllCaps="false" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/category2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:background="#drawable/post_btn_bg"
android:clickable="true"
android:focusable="true"
android:fontFamily="sans-serif"
android:foreground="?android:selectableItemBackground"
android:padding="5dp"
android:text="#string/awareness"
android:textAllCaps="false"
android:textColor="#color/colorPrimary"
android:textSize="10sp"
android:textStyle="normal"
app:layout_constraintStart_toEndOf="#+id/category1"
app:layout_constraintTop_toBottomOf="#+id/view"
app:textAllCaps="false" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/category3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:background="#drawable/post_btn_bg"
android:clickable="true"
android:focusable="true"
android:fontFamily="sans-serif"
android:foreground="?android:selectableItemBackground"
android:padding="5dp"
android:text="#string/scheme"
android:textAllCaps="false"
android:textColor="#color/colorPrimary"
android:textSize="10sp"
android:textStyle="normal"
app:layout_constraintStart_toEndOf="#+id/category2"
app:layout_constraintTop_toBottomOf="#+id/view"
app:textAllCaps="false" />
<View
android:id="#+id/line1"
android:layout_width="match_parent"
android:layout_height="0.4dp"
android:layout_marginTop="8dp"
android:background="#color/grey_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/category3" />
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/write_post"
android:layout_width="match_parent"
android:layout_height="#dimen/dimen_100dp"
android:layout_below="#+id/line1"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/post_edit_text_bg"
android:fontFamily="#font/roboto_regular"
android:gravity="start"
android:hint="What's on your mind..."
android:inputType="textMultiLine"
android:textColor="#color/textview_black"
android:textColorHint="#color/grey2_text"
android:textCursorDrawable="#drawable/cursor_color"
android:textSize="#dimen/dimen_16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/line1" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/timelineImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:visibility="gone"
android:layout_marginBottom="#dimen/dimen_20dp"
app:layout_constraintBottom_toTopOf="#+id/linearLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/write_post">
</androidx.appcompat.widget.AppCompatImageView>
<VideoView
android:id="#+id/timelineVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="#+id/linearLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
android:layout_marginBottom="#dimen/dimen_20dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/write_post"
app:layout_constraintVertical_bias="0.072">
</VideoView>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="8dp"
android:background="#drawable/item_bg"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:foreground="?android:selectableItemBackground"
android:padding="10dp"
android:src="#drawable/ic_camera" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foreground="?android:selectableItemBackground"
android:padding="10dp"
android:src="#drawable/gallery" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
Tried everything in the manifest
android:windowSoftInputMode="adjustPan"
android:windowSoftInputMode="adjustResize"
android:windowSoftInputMode="adjustNothing"
but nothing worked. All are pushing my entire layout up.
I think this is because, you are using NestedScrollView as parent check by replacing NestedScrollView with any other layout
add This in your meniFest file beside your activity tag
android:windowSoftInputMode="adjustResize"
and,put scrollView as a parent layout in your xml file

Making an activity resizable

I have this activity with a Constraint Layout:
And here is the XML :
<?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="#color/colorPrimary"
android:orientation="vertical"
tools:context=".Activity">
<TextView
android:id="#+id/textView4"
android:layout_width="290dp"
android:layout_height="35dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<TextView
android:id="#+id/textView3"
android:layout_width="290dp"
android:layout_height="33dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<SeekBar
android:id="#+id/slider"
style="#style/Widget.AppCompat.SeekBar"
android:layout_width="383dp"
android:layout_height="79dp"
android:layout_marginTop="8dp"
android:hapticFeedbackEnabled="true"
android:indeterminate="false"
android:max="1200"
android:progress="0"
android:scrollbarSize="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView"
app:tickMark="#color/colorAccent" />
<TextView
android:id="#+id/textView"
android:layout_width="197dp"
android:layout_height="80dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="50sp"
android:typeface="normal"
app:fontFamily="sans-serif"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<TextView
android:id="#+id/textView2"
android:layout_width="290dp"
android:layout_height="33dp"
android:layout_marginTop="24dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/Text"
android:layout_width="231dp"
android:layout_height="67dp"
android:layout_marginTop="4dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="25sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/slider" />
<TextView
android:id="#+id/total"
android:layout_width="270dp"
android:layout_height="94dp"
android:layout_marginTop="8dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="60sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/comisionText" />
<Button
android:id="#+id/btn"
android:layout_width="142dp"
android:layout_height="45dp"
android:layout_marginBottom="16dp"
android:background="#drawable/btn_effect"
android:clickable="false"
android:enabled="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/submitBtn"
app:layout_constraintVertical_bias="0.678" />
<Button
android:id="#+id/submitBtn"
android:layout_width="181dp"
android:layout_height="71dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="4dp"
android:background="#drawable/btn_effect"
android:clickable="false"
android:enabled="false"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.508"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/but" />
<EditText
android:id="#+id/but"
android:layout_width="217dp"
android:layout_height="45dp"
android:layout_marginTop="16dp"
android:clickable="false"
android:ems="10"
android:enabled="false"
android:gravity="center_horizontal"
android:inputType="number"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/total" />
</androidx.constraintlayout.widget.ConstraintLayout>
The problem is that when i try it on a smaller screen phone, it cuts off some of the objects from the bottom of the activity. How can i make it resizable so it can fit any screen size? Every object is constrained Top-To-Bottom of the object above it.
You can use ScrollView, so the user can scroll down and see the whole activity. Just wrapping your ConstraintLayout in ScrollView should be enough, like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="#color/colorPrimary"
android:orientation="vertical"
tools:context=".Activity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:orientation="vertical"
tools:context=".Activity">
<TextView
android:id="#+id/textView4"
android:layout_width="290dp"
android:layout_height="35dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<TextView
android:id="#+id/textView3"
android:layout_width="290dp"
android:layout_height="33dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<SeekBar
android:id="#+id/slider"
style="#style/Widget.AppCompat.SeekBar"
android:layout_width="383dp"
android:layout_height="79dp"
android:layout_marginTop="8dp"
android:hapticFeedbackEnabled="true"
android:indeterminate="false"
android:max="1200"
android:progress="0"
android:scrollbarSize="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView"
app:tickMark="#color/colorAccent" />
<TextView
android:id="#+id/textView"
android:layout_width="197dp"
android:layout_height="80dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="50sp"
android:typeface="normal"
app:fontFamily="sans-serif"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView4" />
<TextView
android:id="#+id/textView2"
android:layout_width="290dp"
android:layout_height="33dp"
android:layout_marginTop="24dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/Text"
android:layout_width="231dp"
android:layout_height="67dp"
android:layout_marginTop="4dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="25sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/slider" />
<TextView
android:id="#+id/total"
android:layout_width="270dp"
android:layout_height="94dp"
android:layout_marginTop="8dp"
android:gravity="center_horizontal|center_vertical"
android:textSize="60sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/Text" />
<Button
android:id="#+id/btn"
android:layout_width="142dp"
android:layout_height="45dp"
android:layout_marginBottom="16dp"
android:background="#drawable/btn_effect"
android:clickable="false"
android:enabled="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/submitBtn"
app:layout_constraintVertical_bias="0.678" />
<Button
android:id="#+id/submitBtn"
android:layout_width="181dp"
android:layout_height="71dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="4dp"
android:background="#drawable/btn_effect"
android:clickable="false"
android:enabled="false"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.508"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/but" />
<EditText
android:id="#+id/but"
android:layout_width="217dp"
android:layout_height="45dp"
android:layout_marginTop="16dp"
android:clickable="false"
android:ems="10"
android:enabled="false"
android:gravity="center_horizontal"
android:inputType="number"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/total"
android:importantForAutofill="no" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Anyways, you should use wrap_content and match_parent instead of hard-coded sizes. Your layout needs to be flexible and adapt to different screen sizes, and that's not possible if you're using determined sizes in your layout. Please take a look into Android Developer: Support different screen sizes

How to make a fragment fit in a FrameLayout in all screen sizes?

I am developing an app where I want to show few fragments in a container(Framelayout) one after other. I want my fragments to fit in the framelayout without its parts going out of the screen.
I want this:
But Getting this:
Here is my code snippet:
<android.support.constraint.ConstraintLayout
android:id="#+id/relativeLayout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="24dp"
android:background="#drawable/grey_border_circular_rect"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline3"
app:layout_constraintVertical_bias="0.0">
<FrameLayout
android:id="#+id/fragment_holder"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toTopOf="#+id/elipse1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</FrameLayout>
<android.support.constraint.Guideline
android:id="#+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_end="32dp" />
<ImageView
android:id="#+id/elipse1"
android:layout_width="14dp"
android:layout_height="14dp"
app:layout_constraintEnd_toStartOf="#+id/elipse2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/guideline4"
app:srcCompat="#drawable/ic_elipse_filled"
tools:layout_editor_absoluteY="568dp" />
<ImageView
android:id="#+id/elipse2"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="#+id/elipse1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/elipse1"
app:srcCompat="#drawable/ic_elipse_blank" />
</android.support.constraint.ConstraintLayout>
I can't share the full xml code as I have some restriction on the code. But the Root layout is also a ConstraintLayout.
fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content">
<TextView
android:id="#+id/otpVerificationTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="OTP Verification"
android:textColor="#color/blue"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="#+id/view2"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:background="#color/btn_grey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/otpVerificationTV" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="8dp"
android:text="We sent you a code"
android:textColor="#android:color/black"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/view2" />
<Button
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:background="#color/transparent"
android:text="Resend OTP"
android:textAllCaps="false"
android:textColor="#color/grey_secondary"
android:textSize="20sp"
app:layout_constraintEnd_toStartOf="#+id/view3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView6" />
<View
android:id="#+id/view3"
android:layout_width="3dp"
android:layout_height="30dp"
android:layout_marginStart="10dp"
android:background="#color/grey_secondary"
app:layout_constraintBottom_toBottomOf="#+id/textView7"
app:layout_constraintEnd_toStartOf="#+id/textView7"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/textView5" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textColor="#color/blue"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBaseline_toBaselineOf="#+id/textView5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/view3"
tools:text="29 sec" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="56dp"
android:text="OTP"
android:textColor="#android:color/black"
android:textSize="26sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView5" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="262dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:background="#color/blue"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="#+id/textView8"
app:layout_constraintTop_toBottomOf="#+id/textView8" />
<Button
android:id="#+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="72dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="#drawable/blue_circular_rect"
android:elevation="#dimen/btn_elevation"
android:text="Next"
android:textAllCaps="false"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/linearLayout"
app:layout_constraintTop_toBottomOf="#+id/linearLayout" />
</android.support.constraint.ConstraintLayout>
So is there any possible way that I can make the fragment fit on any screen size and all of it is visible inside the framelayout.
Below code will help with your fragment.xml file.
You didn't provided more values files means color code, string file and other. So below are some changes from your file like drawable and value related data.
Fill free to put comment if you have any question related to below views. If below code work for you then please approve this answer.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">
<TextView
android:id="#+id/otpVerificationTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="OTP Verification"
android:textColor="#android:color/holo_blue_light"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="#+id/view2"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:background="#color/colorGrey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/otpVerificationTV" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="We sent you a code"
android:textColor="#android:color/black"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="#id/group2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/group2" />
<android.support.constraint.Group
android:id="#+id/group2"
android:layout_width="match_parent"
android:layout_height="0dp"
app:constraint_referenced_ids="textView6"
app:layout_constraintBottom_toTopOf="#id/group"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/view2" />
<android.support.constraint.Group
android:id="#+id/group"
android:layout_width="match_parent"
android:layout_height="0dp"
app:constraint_referenced_ids="view3,textView7,textView5"
app:layout_constraintBottom_toTopOf="#id/group1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/group2" />
<android.support.constraint.Group
android:id="#+id/group1"
android:layout_width="match_parent"
android:layout_height="0dp"
app:constraint_referenced_ids="linearLayout,textView8"
app:layout_constraintBottom_toTopOf="#id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/group" />
<Button
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:text="Resend OTP"
android:textAllCaps="false"
android:textColor="#color/colorGrey"
android:textSize="20sp"
app:layout_constraintEnd_toStartOf="#+id/view3"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="#id/group"
app:layout_constraintTop_toTopOf="#+id/group" />
<View
android:id="#+id/view3"
android:layout_width="3dp"
android:layout_height="30dp"
android:layout_marginStart="10dp"
android:background="#color/colorGrey"
app:layout_constraintBottom_toBottomOf="#+id/textView7"
app:layout_constraintEnd_toStartOf="#+id/textView7"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/textView5" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textColor="#android:color/holo_blue_light"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBaseline_toBaselineOf="#+id/textView5"
app:layout_constraintEnd_toEndOf="#id/group"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/view3"
tools:text="29 sec" />
<TextView
android:id="#+id/textView8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:text="OTP"
android:textColor="#android:color/black"
android:textSize="26sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/group1" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="262dp"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:background="#android:color/holo_blue_light"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="#+id/textView8"
app:layout_constraintTop_toBottomOf="#+id/textView8" />
<Button
android:id="#+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="#android:color/holo_blue_light"
android:elevation="1dp"
android:text="Next"
android:textAllCaps="false"
android:textColor="#android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/linearLayout"
app:layout_constraintTop_toBottomOf="#+id/group1" />
</android.support.constraint.ConstraintLayout>

Categories

Resources