Question

I want to scroll up my layout when softinput keyboard is visible.I have define scrollview in my xml at proper place but when keyboard is visible it hides some part of layout like buttons. I have read on stackoveflow Link that scrollview not works when activity is FULL_SCREEN.If it is true then how can I scroll up my layout when softinput visible.

Was it helpful?

Solution

Use this custom relative layout to detect softkeyboard with in ur xml

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

 /**
 * RelativeLayout that can detect when the soft keyboard is shown and hidden.
 *  
 */

public class RelativeLayoutThatDetectsSoftKeyboard extends RelativeLayout {

public RelativeLayoutThatDetectsSoftKeyboard(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public interface Listener {
    public void onSoftKeyboardShown(boolean isShowing);
}
private Listener listener;
public void setListener(Listener listener) {
    this.listener = listener;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int height = MeasureSpec.getSize(heightMeasureSpec);
    Activity activity = (Activity)getContext();
    Rect rect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
    int statusBarHeight = rect.top;
    int screenHeight = activity.getWindowManager().getDefaultDisplay().getHeight();
    int diff = (screenHeight - statusBarHeight) - height;
    if (listener != null) {
        listener.onSoftKeyboardShown(diff>128); // assume all soft keyboards are at least 128 pixels high
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);       
}

}

Then implements RelativeLayoutThatDetectsSoftKeyboard.Listener to your Actiity class

   RelativeLayoutThatDetectsSoftKeyboard mainLayout =  (RelativeLayoutThatDetectsSoftKeyboard)V.findViewById(R.id.dealerSearchView);
   mainLayout.setListener(this);




    @Override
public void onSoftKeyboardShown(boolean isShowing) {
    if(isShowing) {


    } else {

    }
}

Based on the Keyboard visibility move your layout to up and down using Layout params

OTHER TIPS

you have to change your manifest file

in your activity tag

android:windowSoftInputMode="adjustPan" add this.

see this http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top