2
votes

my scroll view contains a linear layout which further contains some of the edit text fields. now when I click on a edit text field at the bottom one then soft keyboard appears, but my problem is that it covers that edit textfield. this is my activity declared in android manifest file:

<activity android:name="me.example.scrollview.LoginActivity" android:label="@string/title_activity_login" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" > </activity>

and here is my layout.xml file for this activity.

<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="match_parent"
android:background="@android:color/darker_gray"
tools:context=".LoginActivity" >

<ScrollView
    android:id="@+id/login_sv_login_container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:isScrollContainer="true"
    android:background="@android:color/transparent" >

    <LinearLayout
        android:id="@+id/login_ll_container"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="230dp"
        android:layout_gravity="center_horizontal"
        android:background="@android:color/transparent"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/txt_username"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/rounded_edittext"
            android:ems="10"
            android:inputType="textEmailAddress"
            android:maxLines="1"
            android:singleLine="true" >

            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/txt_phone"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/rounded_edittext"
            android:ems="10"
            android:inputType="phone"
            android:maxLines="1"
            android:singleLine="true" />

        <EditText
            android:id="@+id/txt_password"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/rounded_edittext"
            android:ems="10"
            android:inputType="textPassword"
            android:maxLines="1"
            android:singleLine="true" />

        <Button
            android:id="@+id/btn_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_marginTop="10dp"
            android:background="@drawable/ic_login"
            android:text="" />
    </LinearLayout>
</ScrollView>

Now Please help me as I am very new to android programming. I am unable to fix this issue and can't find a way to scroll my scroll view without resizing my main window.I just want my scroll view to make scrolling when soft keyboard appears.Thanx in advance.

enter image description here

3

3 Answers

0
votes

Both previously pointed out solutions can work. But there might still be a problem if the edittext is at the bottom of the ListView where it would still be covered by the onscreen keyboard. Not sure if a scrollview can be scrolled to a point where there is no more content.

What i've seen is that you might use two contradicting flags in your manifest:

android:windowSoftInputMode="stateHidden|adjustResize|adjustPan" > </activity>

adjustResize and adjustPan can imho NOT be combined. Try how it looks with only adjustResize. This should avoid that the keyboard covers anything of your view.

0
votes

You can try:

ScrollView scroll = (ScrollView)findViewById(R.id.scrollview);
scroll.scrollTo(0, sv.getBottom());

or

scroll.scrollTo(5, 10);
0
votes

You can use YOURSCROLLVIEW.scrollTo(int x, int y) or YOURSCROLLVIEW.smoothScrollTo(int x, int y) to move the scroll view to the appropriate coordinates so that the edit text box and keyboard are both shown.

More information about these functions and other scrollview functions can be found on the android developer reference page.