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> 
0

3 Answers 3

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> 
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

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; } }); 

1 Comment

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.