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.
Asked
Active
Viewed 4,281 times
4
-
show us your code plz – Iftikar Urrhman Khan May 15 '13 at 09:21
-
-
may be this will help http://stackoverflow.com/questions/11298479/can-not-get-scrollview-to-scroll-when-soft-keyboard-is-shown make your scroll view parent – Iftikar Urrhman Khan May 15 '13 at 09:30
2 Answers
1
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

OMAK
- 1,031
- 9
- 25
0
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

Iftikar Urrhman Khan
- 1,131
- 1
- 10
- 21
-
I have already define android:windowSoftInputMode="stateVisible|adjustResize|adjustPan" but still its not working – Nitish Patel May 15 '13 at 09:19