0

Every time the keyboard opens it pushes my root constraint layout up off the screen.

This is it normally

enter image description here

Then when i click a span it brings up a little control panel thing at the bottom like so, note the top of the screen with the title.

enter image description here

now when i click the edit text to type my answer it pushes everything up and the highest i can scroll is here, its like the top of the scrollview is up off the top of the screen. i can no longer see the title or question 1. This is with adjustPan set in the manifest. Ive tried to change it to adjust resize as i thought that would resize the views height but it makes it worse.

enter image description here

here is my xml:

<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/questionRoot"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="?android:attr/colorBackground"
    android:clickable="true"
    android:focusable="true">

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="@+id/actionFrameLayout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <RelativeLayout
            android:id="@+id/relativeLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/questionTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="48dp"
                android:layout_marginEnd="16dp"
                android:textAlignment="viewStart"
                android:textColor="#353535"
                android:textSize="18sp"
                android:textStyle="bold"
                tools:text="Title" />

            <TextView
                android:id="@+id/questionBody"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/questionTitle"
                android:layout_marginStart="16dp"
                android:layout_marginTop="24dp"
                android:layout_marginEnd="16dp"
                android:layout_marginBottom="8dp"
                android:lineSpacingExtra="10dp"
                android:paddingBottom="32dp"
                android:textSize="16sp" />

        </RelativeLayout>

    </ScrollView>

    <View
        android:id="@+id/topBorder"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#D3D3D3"
        app:layout_constraintBottom_toTopOf="@id/frameLayout"
        />

    <View
        android:id="@+id/bottomBorder"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#D3D3D3"
        app:layout_constraintBottom_toBottomOf="parent"
        />


    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:background="@color/white"
        app:layout_constraintBottom_toTopOf="@id/bottomBorder"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

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

            <Button
                android:id="@+id/showTimer"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Timer" />

            <Button
                android:id="@+id/finishTestButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Finish" />

        </LinearLayout>

    </FrameLayout>

    <FrameLayout
        android:id="@+id/actionFrameLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@id/frameLayout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent">

    </FrameLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

edit: this is what setting the manifest file with adjustResize does :

enter image description here

Dave
  • 313
  • 1
  • 3
  • 16
  • 1
    Have you tested a different height other than `android:layout_height="0dp"` in your `ScrollView`? – JorgeAmVF May 08 '19 at 09:57
  • 1
    @JorgeAmVF yes i have, tried all different heights including 'wrap content'. i might end up changing the layout if i cant work it out. I been looking at it on and off now for days! This is first time using a scroll view so maybe im doing something wrong with it – Dave May 08 '19 at 10:22
  • 1
    besides the `layout_height`, other thing that pops up and I'd try is to get rid of `ConstraintLayout` related stuff in the `ScrollView` because the way they work sometimes is uncomfortable and something might be getting confused or something like that. – JorgeAmVF May 08 '19 at 10:30

1 Answers1

0

I was dealing with a similar issue in a WebView Fragment and the solution was the following code inserted inside my main activity class onCreate:

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

If you want to try something from the Manifest level, you could try:

    android:windowSoftInputMode="adjustPan"

Hope it helps you as well as it helped me!

JorgeAmVF
  • 1,660
  • 3
  • 21
  • 32
  • 1
    Thats what i've currently got it set as, im stumped. I think it has something to do with the layout file but ive tried everything i can think of – Dave May 08 '19 at 08:18
  • 1
    Sorry, @Dave, I thought `SOFT_INPUT_ADJUST_PAN` programmatically could be enough to divert from any issues related with the `Manifest`; if you think it has to do with the layout, you could try changing the style like [this answer](https://stackoverflow.com/a/31742154/6398434) suggests or the layout following [this other one](https://stackoverflow.com/a/31994697/6398434), for instance; at least in my case, answers from [this question](https://stackoverflow.com/q/1964789/6398434) were enough to overcome the problem. – JorgeAmVF May 08 '19 at 09:15
  • all these questions seem to have something to do with relative layouts? i might swap mine out for a different layout inside the scrollview and see if that works. thanks – Dave May 08 '19 at 10:26
  • 1
    You're welcome, @Dave: I hope it helps. The best of luck! – JorgeAmVF May 08 '19 at 10:32