1

I am using this code. However when ever i click on EditText to open the keyboard, the view is not totally up. Why the view is not going up all the way, EditText is hidden behind Keyboard

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    android:background="@drawable/main_bg" 
    android:id="@+id/mainLayout"
    android:focusableInTouchMode="true"
    >

       <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:orientation="horizontal"
        android:id="@+id/topBar"
        android:background="@drawable/top_bar_bg"
     >

        <LinearLayout 
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:orientation="horizontal"
                android:gravity="center_horizontal|bottom"
                android:layout_centerInParent="true"
            >

                 <ImageView 
                     android:id="@+id/loadingAnimationImg"
                     android:layout_height="35dp"
                     android:layout_width="35dp"
                     android:adjustViewBounds="true"
                     android:contentDescription="@null"
                     android:background="@drawable/img05"/>

                 <ImageView 
                     android:layout_marginBottom="5dp"
                     android:layout_height="wrap_content"
                     android:layout_width="120dp"
                     android:adjustViewBounds="true"
                     android:contentDescription="@null"
                     android:src="@drawable/simple_logo"/>

         </LinearLayout>
    </RelativeLayout>

    <GridView
            android:layout_marginTop="5dp"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:id="@+id/gridView"
            android:numColumns="5"
            android:verticalSpacing="5dp" />

    <TextView 
        android:layout_marginTop="5dp"
        android:layout_marginLeft="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:textColor="@android:color/white"
        android:text="@string/hashtagText"
        />


    <com.trib.devicebee.custom.FlowLayout 
        android:id="@+id/flowLayout"
        android:layout_margin="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

    <EditText 
        android:layout_margin="10dp"
        android:id="@+id/hashTagsText"
        android:hint=""
        android:inputType="textFilter" 
        android:singleLine="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        />

    <Button
        android:id="@+id/goAheadBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/go_ahead_btn"
        android:layout_margin="10dp"
         />

</LinearLayout>
Fabricio Lemos
  • 2,905
  • 2
  • 31
  • 31
Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193

3 Answers3

5

The best solution I came up with is to put everything in scrollView.

  • Now in manifest

    <activity
        android:name="MyActivity"
        android:windowSoftInputMode="adjustResize">
    </activity>
    
  • Now use the onfocusChangeListener on the editText you want to focus

    editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean b) {
            if (b){
            scrollView.smoothScrollTo(0,editText.getBottom()+5);
            }
        }
    });
    

And we are done.

Pang
  • 9,564
  • 146
  • 81
  • 122
Sarthak Gandhi
  • 2,130
  • 1
  • 16
  • 23
  • Please do not [copy and paste answers](http://stackoverflow.com/questions/3295672/android-soft-keyboard-covers-edittext-field/39357566#39357566) between questions. If the same answer applies to both questions, one question should be flagged as a duplicate, not answered. – miken32 Sep 06 '16 at 20:51
4

Try to play with android:windowSoftInputMode attribute in AndroidManifest.xml - "adjustPan" could be the answer.

<activity
    android:name="MyActivity"
    android:windowSoftInputMode="adjustPan"
    android:configChanges="orientation|keyboardHidden|screenSize"
    >
</activity>
Quark
  • 1,578
  • 2
  • 19
  • 34
-1

https://developer.android.com/training/keyboard-input/visibility.html

android:windowSoftInputMode="adjustResize"

mjstam
  • 1,049
  • 1
  • 6
  • 5