0

This is more like the general information question that I am asking I tried to implement windowSoftinputMode="adjustResize" mode in constraint layout but it doesn't work for it at all I tried to search for a constraint layout example but there is no example available on the internet. The only example I am able to find is with relative layout and when I implemented it worked like a charm so please tell me why it works like that

here is my constraint layout code

<?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"
    tools:context=".MainActivity">


    <TextView
        android:id="@+id/fromtext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="140dp"
        android:fontFamily="@font/nunito_sans_semibold"
        android:text="@string/from"
        android:textSize="@dimen/_15sdp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Spinner
        android:id="@+id/fromSpinner"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_35sdp"
        android:layout_marginHorizontal="@dimen/_20sdp"
        android:entries="@array/weight"
        android:textAlignment="center"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.49"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/fromtext"
        app:layout_constraintVertical_bias="0.085" />

    <com.google.android.material.textfield.TextInputLayout

        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/_15sdp"
        android:id="@+id/fromvalue"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/fromSpinner"
        app:layout_constraintVertical_bias="0.0"
        tools:layout_editor_absoluteX="13dp">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:textAlignment="center"
            android:textSize="@dimen/_15sdp" />

    </com.google.android.material.textfield.TextInputLayout>

    <TextView
        android:id="@+id/totext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/_50sdp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_gravity="center"
        android:text="@string/to"
        app:layout_constraintTop_toBottomOf="@+id/fromvalue"
        android:textSize="@dimen/_20sdp"/>


    <Spinner
        android:layout_width="match_parent"
        android:layout_height="@dimen/_35sdp"
        android:layout_margin="@dimen/_15sdp"
        android:entries="@array/weight"
        app:layout_constraintTop_toBottomOf="@+id/totext"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:textAlignment="center"
        android:id="@+id/toSpinner"/>


    <com.google.android.material.textfield.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/toSpinner"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_margin="@dimen/_15sdp"
        >

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/tovalue"
            android:layout_width="match_parent"
            android:focusable="false"
            android:textSize="@dimen/_20sdp"
            android:textAlignment="center"
            android:cursorVisible="false"
            android:layout_height="wrap_content" />

    </com.google.android.material.textfield.TextInputLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

update Now my app behaves like this when the keyboard is hidden

enter image description here

when the keyboard is not hidden

enter image description here

i want my screen to be fully resized not just one element

Naveen Singla
  • 76
  • 1
  • 8
  • Do you set `windowSoftinputMode="adjustResize"` in manifest? – Zain Mar 18 '22 at 19:34
  • @Zain yess i even tried adjust pan property too – Naveen Singla Mar 18 '22 at 20:26
  • I'd similar issue and solved by setting it programmatically; try to `window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)` – Zain Mar 18 '22 at 20:33
  • I added these lines in my activity java file but now the app keeps crashing **Window window** **window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);** – Naveen Singla Mar 19 '22 at 06:12
  • For java use `getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)` – Zain Mar 19 '22 at 10:35
  • @Zain now it is kind away because now it is only resizing the text fields which are getting covered by the keyboard but I want the whole screen to be resized – Naveen Singla Mar 19 '22 at 15:07
  • I think you need to `getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)` instead – Zain Mar 19 '22 at 17:26
  • @Zain now it doesn't work at all is there some layout condition that we need to follow so that adjustpan or adjustResize can work maybe i myself can figure it out – Naveen Singla Mar 19 '22 at 17:39

0 Answers0