7

I have a textview that is inside of a scrollview, it scrolls fine untill the soft keyboard is opened.

When the keyboard is opened it act like it scrolled up again with the height of the keyboard.

What I have tried

I tried this in the manifest, but yielded the exact same results

android:windowSoftInputMode="adjustResize"

Then this:

android:windowSoftInputMode="adjustPan"

That seemed to work, but the problem was that it was moving the whole screen up and taking the header out of view.

I also tried adding the following in the linear layout

android:focusable="true"
android:focusableInTouchMode="true"

That only caused the app not to focus on the input field (EditText) and the keyboard didn't open automatically, but when you clicked on the input field it would just act the same as before.

This is the XML file code:

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

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/bottom_layout"
    android:layout_marginTop="10dip" >

    <LinearLayout
        android:id="@+id/msg_list_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    </LinearLayout>
</ScrollView>

<RelativeLayout
    android:id="@+id/bottom_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@android:color/background_light">
    <Button
        android:id="@+id/send_btn"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="@string/txt_send" />

    <EditText
        android:id="@+id/msg_edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/send_btn"
        android:layout_toLeftOf="@+id/send_btn"
        android:inputType="text" >
    </EditText>
</RelativeLayout>

Any suggestions?

Shaun
  • 559
  • 1
  • 3
  • 17
  • I had this issue with a HorizontalScrollView. [Check my answer][1] [1]: http://stackoverflow.com/a/28341373/1912919 – gtsouk Feb 05 '15 at 10:21
  • for Android 5, check out this related post: [Android - adjust scrollview when keyboard is up for android 5.0 (lollipop)](http://stackoverflow.com/questions/27167176/android-adjust-scrollview-when-keyboard-is-up-for-android-5-0-lollipop) – Richard Le Mesurier Nov 27 '15 at 07:49

4 Answers4

23

I had same problem and the solutions is this: My activity was in fullscreen mode and scroll does not work in this mode this is a bug and we send a report to google. Just look at your activity in manifest if there is a fullscreen mode just remove it.

HK.avdalyan
  • 724
  • 1
  • 6
  • 21
2

I got this problem and it is a headache.
the soloution is instead of drawing an XML layout from the top of the screen, you need to draw it from the bottom of the screen.

look at these examples :

main.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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:isScrollContainer="true"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <include layout="@layout/main_contents"/>
    </ScrollView>

</android.support.constraint.ConstraintLayout>

main_contents.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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="20dp">

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.92" />


    <android.support.v7.widget.CardView
        android:id="@+id/card1"
        android:layout_width="0dp"
        android:layout_height="250dp"
        android:layout_margin="30dp"
        android:padding="10dp"
        app:cardCornerRadius="10dp"
        app:layout_constraintBottom_toTopOf="@+id/guideline"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/sam3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:text="sample"
                android:textColor="#673AB7"
                android:textSize="23sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />



                <EditText
                    android:id="@+id/sam2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|center_vertical"
                    android:backgroundTint="#673AB7"
                    android:digits="0123456789"
                    android:gravity="center"
                    android:hint="sample"
                    android:inputType="phone"
                    android:maxLength="11"
                    android:maxLines="1"
                    android:nextFocusDown="@id/sam1"
                    android:textColor="#673AB7"
                    android:layout_marginStart="40dp"
                    android:layout_marginEnd="40dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/sam3"
                    app:layout_constraintVertical_bias="0.3"/>


        </android.support.constraint.ConstraintLayout>
    </android.support.v7.widget.CardView>


    <Button
        android:id="@+id/sam1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:textColor="#fff"
        android:background="#673AB7"
        android:text="sample"
        android:layout_marginLeft="60dp"
        android:layout_marginRight="60dp"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="@+id/card1"
        app:layout_constraintEnd_toEndOf="@+id/card1"
        app:layout_constraintStart_toStartOf="@+id/card1"
        app:layout_constraintTop_toBottomOf="@+id/card1" />


</android.support.constraint.ConstraintLayout>

main_contents2.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="match_parent"
    android:paddingBottom="20dp">

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.45" />


    <android.support.v7.widget.CardView
        android:id="@+id/card1"
        android:layout_width="0dp"
        android:layout_height="250dp"
        android:layout_margin="30dp"
        android:padding="10dp"
        app:cardCornerRadius="10dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <EditText
                android:id="@+id/sam2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="right|center_vertical"
                android:layout_marginStart="40dp"
                android:layout_marginEnd="40dp"
                android:backgroundTint="#673AB7"
                android:digits="0123456789"
                android:gravity="center"
                android:hint="sample"
                android:inputType="phone"
                android:maxLength="11"
                android:maxLines="1"
                android:nextFocusDown="@id/sam1"
                android:textColor="#673AB7"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/sam3"
                app:layout_constraintVertical_bias="0.3" />


            <TextView
                android:id="@+id/sam3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:text="sample"
                android:textColor="#673AB7"
                android:textSize="23sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />


        </android.support.constraint.ConstraintLayout>
    </android.support.v7.widget.CardView>


    <Button
        android:id="@+id/sam1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:textColor="#fff"
        android:background="#673AB7"
        android:text="sample"
        android:layout_marginLeft="60dp"
        android:layout_marginRight="60dp"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="@+id/card1"
        app:layout_constraintEnd_toEndOf="@+id/card1"
        app:layout_constraintStart_toStartOf="@+id/card1"
        app:layout_constraintTop_toBottomOf="@+id/card1" />


</android.support.constraint.ConstraintLayout>

the second XML file main_contents2 drew from top and android just put the EditText from top of the keyboard.BUT the main_contents drawn from the bottom of the screen. so when the soft keyboard comes up the layout resizes.

1

Try changing the layout_height of scrollview to wrap_content.

Manoj Reddy
  • 134
  • 8
0

All you need to do is

android:isScrollContainer="true"
Pankaj Talaviya
  • 3,328
  • 28
  • 31