jelmood jasser
jelmood jasser

Reputation: 918

Keyboard hides EditText inside a ScrollView in android?

I have nested LinearLayouts which one of them has group of vertical EditText inside a ScrollView. The problem Every time I click one of those EditText and the Keyboard in android arises half of those EditText disappear and if I write in the first Edit Text, I cannot even see it or scroll into it.

I have tried different solution mention here in Stackoverflow like adding android:windowSoftInputMode="adjustPan|adjustResize" but to no avail.

Here is my MainActivity.xml

 LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <ImageView
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginTop="10dp"
        android:src="@drawable/clac"
        android:scaleType="centerCrop"
        android:layout_gravity="center"
        />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center"
        android:layout_marginTop="16dp"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Letter Grade"
            android:textSize="15sp"

            />
        <TextView

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Credit Hours"
            android:textSize="15sp"
            android:layout_marginLeft="60dp"
            />
    </LinearLayout>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:focusable="true"
        android:focusableInTouchMode="true">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_gravity="center"
    android:id="@+id/inputform">

    <LinearLayout

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
android:layout_gravity="center"

        >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:orientation="vertical">


            <EditText
                android:layout_marginTop="10dp"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/crs1" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/crs2" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/crs3" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/crs4" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/crs5" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/crs6" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/crs7" />

        </LinearLayout>





        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="64dp"
            android:orientation="vertical"
            >

            <EditText
                android:layout_marginTop="10dp"
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/credit1" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/credit2" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/credit3" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/credit4" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/credit5" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/credit6" />
            <EditText
                android:gravity="center"
                android:layout_height="wrap_content"
                android:layout_width="48dp"
                android:layout_gravity="center"
                android:id="@+id/credit7" />

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

        </LinearLayout>
    </LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_marginTop="28dp"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Current GPA"
        android:layout_marginLeft="20dp"/>
    <EditText

        android:layout_height="wrap_content"
        android:layout_width="48dp"
        android:layout_marginLeft="5dp"
        android:id="@+id/currentgpa"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Taken Hours"
        android:layout_marginLeft="20dp"/>
    <EditText

        android:layout_height="wrap_content"
        android:layout_width="48dp"
        android:layout_marginLeft="8dp"
        android:id="@+id/currenthours"/>

</LinearLayout>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="16dp">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Reset"
        android:onClick="clearForm"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Calculate"
        android:onClick="Calculate"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="GPA"
        android:layout_marginLeft="30dp"
        android:id="@+id/gpa"/>

</LinearLayout>

</LinearLayout>
</ScrollView>
</LinearLayout>

Thank you I appreciate any help.

Upvotes: 4

Views: 4935

Answers (4)

maciej
maciej

Reputation: 357

I build your code on my device and adding android:windowSoftInputMode="adjustPan"in Manifest file helps

IN your xml file

something something

   <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:focusable="true"
    android:gravity="center_horizontal"
    android:focusableInTouchMode="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center_horizontal"
        android:id="@+id/inputform"
        >

        <LinearLayout

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"

            >

something something

I just searched in google "scrollview cut edittext" and answer comes up. You are a programmer, you must make things done by yourself ;)

Upvotes: 0

wqycsu
wqycsu

Reputation: 390

It happens because your buttons layout is included in the scrollview, so when the keyboard appears the buttons layout will occupy some space. You can change your layout like this:(set the windowSoftInputMode as adjustPan)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <ImageView
        android:id="@+id/img"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:scaleType="centerCrop"
        android:src="@mipmap/ic_launcher" />

    <LinearLayout
        android:id="@+id/title"
        android:layout_below="@id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Letter Grade"
            android:textSize="15sp"

            />

        <TextView

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="60dp"
            android:text="Credit Hours"
            android:textSize="15sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/buttons"
        android:layout_alignParentBottom="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="clearForm"
            android:text="Reset" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="Calculate"
            android:text="Calculate" />

        <TextView
            android:id="@+id/gpa"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:text="GPA" />

    </LinearLayout>

    <ScrollView
        android:id="@+id/scrollview"
        android:layout_below="@id/title"
        android:layout_above="@id/buttons"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:focusable="true"
        android:focusableInTouchMode="true">

        <LinearLayout
            android:id="@+id/inputform"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="vertical">

            <LinearLayout

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:orientation="horizontal"

                >

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"

                    android:orientation="vertical">


                    <EditText
                        android:id="@+id/crs1"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="10dp"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/crs2"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/crs3"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/crs4"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/crs5"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/crs6"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/crs7"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                </LinearLayout>


                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="64dp"
                    android:orientation="vertical">

                    <EditText
                        android:id="@+id/credit1"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginTop="10dp"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/credit2"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/credit3"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/credit4"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/credit5"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/credit6"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                    <EditText
                        android:id="@+id/credit7"
                        android:layout_width="48dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:gravity="center" />

                </LinearLayout>

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

                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="28dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:text="Current GPA" />

                <EditText

                    android:id="@+id/currentgpa"
                    android:layout_width="48dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="20dp"
                    android:text="Taken Hours" />

                <EditText

                    android:id="@+id/currenthours"
                    android:layout_width="48dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="8dp" />

            </LinearLayout>



        </LinearLayout>
    </ScrollView>

</RelativeLayout>

Upvotes: 0

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75798

According to your problem use following in your activity manifest

<activity android:windowSoftInputMode="adjustPan"> </activity>

adjustPan

The activity's main window is not resized to make room for the soft keyboard. For more information about this please visit

http://developer.android.com/guide/topics/manifest/activity-element.html

Upvotes: 5

Darshan Mistry
Darshan Mistry

Reputation: 3372

you have only declare android:windowSoftInputMode="adjustPan" in your manifeast file remove adjustResize from manifeast.

Upvotes: 1

Related Questions