1

i have a simple Relative xml with One TextView And One EditText but when user touch the EditText and when keyboard comes up my Text view Goes Up and disappear.. how can i make it to always stay at Center?

here is my XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="20dp"
    tools:context="com.example.testtypecounter.MainActivity"
    tools:ignore="MergeRootFrame" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/CurrentView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="hjk"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="40sp" />

</RelativeLayout>
Lal
  • 14,726
  • 4
  • 45
  • 70
Saeed74
  • 65
  • 1
  • 10

3 Answers3

4

From the doc

android:windowSoftInputMode=["stateUnspecified",
                                       "stateUnchanged", "stateHidden",
                                       "stateAlwaysHidden", "stateVisible",
                                       "stateAlwaysVisible", "adjustUnspecified",
                                       "adjustResize", "adjustPan"]

"adjustResize"=>

The activity's main window is always resized to make room for the soft keyboard on screen.

"adjustPan"=>

The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

You may have to use following in your activity manifest

<activity android:windowSoftInputMode="adjustResize"> </activity>
Lal
  • 14,726
  • 4
  • 45
  • 70
2

Add android:windowSoftInputMode="adjustResize" to your activity tag in the manifest.

Shivam Verma
  • 7,973
  • 3
  • 26
  • 34
1

Try this...

ScrollView scroll = (ScrollView)findViewById(R.id.scrollView1);
scroll.setOnTouchListener(new OnTouchListener() {

   @Override
   public boolean onTouch(View v, MotionEvent event) {
      if (myEditText.hasFocus()) {
         myEditText.clearFocus();
      }
      return false;
   }
});
vdelll
  • 29
  • 6
user3740085
  • 244
  • 1
  • 9
  • 1
    May refer this link..http://stackoverflow.com/questions/6176391/stop-scrollview-from-auto-scrolling-to-an-edittext – user3740085 Jul 02 '14 at 17:02