2

I just want to know if you have already encounter this issue in edittext when you set the gravity to "center" the keyboard overlap the edittext. Hope you could help me fix this problem.

I added my code below.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/img_splash"
android:gravity="bottom"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

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

        <EditText
            android:id="@+id/edit_username"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_marginBottom="13dp"
            android:background="@drawable/img_textfield"
            android:ems="10"
            android:gravity="center_vertical|center_horizontal"
            android:hint="Username"
            android:imeOptions="actionNext"
            android:maxLines="1"
            android:singleLine="true"
            android:textSize="18sp" />

        <EditText
            android:id="@+id/edit_password"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:layout_marginBottom="28dp"
            android:background="@drawable/img_textfield"
            android:ems="10"
            android:gravity="center_vertical|center_horizontal"
            android:hint="Password"
            android:inputType="textPassword"
            android:maxLines="1"
            android:singleLine="true"
            android:textSize="18sp" />
    </LinearLayout>
</ScrollView>

<Button
    android:id="@+id/button_login"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_marginBottom="75dp"
    android:background="@drawable/btn_login"
    android:onClick="onClicked"
    android:text="Login"
    android:textColor="@color/white_pure"
    android:textSize="18sp" />

 </LinearLayout>
Mobi10
  • 41
  • 5
  • This is not about gravity issue. you can set `android:windowSoftInputMode="adjustResize|adjustPan"` into your activity in `manifest.xml` file. – M D Feb 12 '14 at 04:17
  • 1
    I tried this already but it push the whole layout upward which is not good. – Mobi10 Feb 12 '14 at 04:34
  • try this separately `adjustPan` and `adjustResize` – M D Feb 12 '14 at 04:36
  • 1
    I tested also this edittext gravity, I created two edittext, the edittext1 is set to center and edittext2 is set to default. This two edittext is align to bottom and I always got the same result, I'm using s4 – Mobi10 Feb 12 '14 at 04:36
  • Put both `EditText` into `ScrollView` and try and also upload your layout – M D Feb 12 '14 at 04:38
  • I still got the same result, it push the whole layout upward which is not good. – Mobi10 Feb 12 '14 at 04:52
  • then what u want to do? – M D Feb 12 '14 at 04:54
  • I encountered this for android greater than version 4.4, any resolution on this? – bmkay Nov 27 '14 at 21:05
  • a strange bug in android but I can confirm it. I tried to solve it by setting gravity to left before programmatically focus the EditText, and 300ms after focusing it (using Handler.postDelayed()), when the keyboard is visible, setting it to center again. But on some devices it would sill not work :( – Moritz Both Aug 11 '16 at 06:39
  • This is an Android bug, look at this post: http://stackoverflow.com/questions/15317157/android-adjustpan-not-working-after-the-first-time – Oleksandr Bodashko Dec 02 '16 at 14:37

1 Answers1

-1

Try using

android:windowSoftInputMode="adjustResize|stateHidden" in manifest

Or put your view inside a scrollview

Source

Viswanath Lekshmanan
  • 9,945
  • 1
  • 40
  • 64