My activity have a top bar and a bottom bar. the space between topbar and bottom bar i have a linearlayout with several edittext views inside. Because i don't want my layout resize every time the softkeyboard show up, so i set android:windowSoftInputMode="adjustPan" for my activity in manifest. But when the softkeyboard is openned, i want to scroll down to select another edittext to input, it's not allow me do that. Im only able to select the edittext at bottom when i close the softkeyboard. That's very annoying and inconvenient. How can i get both scrollview and ajustpan mode for softkeyboard work well together?
Please help me out. thanks you so much.
Posted on October 25, 2010 by Lars Vogel. Android has the so-called Input Method Framework to support different input methods, e.g. keyboard, soft-keyboard, handwriting etc. If the soft-keyboard is used it is diplayed at the bottom of the screen once the user select an text view to edit it.
At last, i find out a workaround for my problem, so i want to share for someone maybe get the same problem in future. A brief description of my layout as following:
<myRelativeLayout>
<topbar.../>
<myscrollView>
<linearLayout>
//all stuff controls:editview,textview,....
</linearLayout>
</myscrollView>
<bottombar.../>
i create custom class myRelativeLayout extend RelativeLayout
public class myRelativeLayout extends RelativeLayout{
public interface OnRelativeLayoutChangeListener {
void onLayoutPushUp();
void onLayoutPushDown();
}
private OnRelativeLayoutChangeListener layoutChangeListener;
public myRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int proposedheight = MeasureSpec.getSize(heightMeasureSpec);
final int actualHeight = getHeight();
if (actualHeight > proposedheight){
// Keyboard is shown
layoutChangeListener.onLayoutPushUp();
} else if(actualHeight < proposedheight){
// Keyboard is hidden
layoutChangeListener.onLayoutPushDown();
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
public void setLayoutChangeListener(OnRelativeLayoutChangeListener layoutChangeListener) {
this.layoutChangeListener = layoutChangeListener;
}
public OnRelativeLayoutChangeListener getLayoutChangeListener() {
return layoutChangeListener;
}
}
And in my activity , i just set setLayoutChangeListener for myRelativeLayout to hide bottombar when softkeyboard show up and display bottombar when softkeyboard hide:
myRlayout.setLayoutChangeListener(new OnRelativeLayoutChangeListener() {
@Override
public void onLayoutPushUp() {
// TODO Auto-generated method stub
myBottombar.setVisibility(View.GONE);//in my case i need to setVisibility(View.GONE) to bottombar in order for this bar is not displayed when softkeyboard show up.
}
@Override
public void onLayoutPushDown() {
// TODO Auto-generated method stub
myBottombar.setVisibility(View.VISIBLE);// redisplay myBottombar when keyboard is closed.
}
});
Dont forget set android:windowSoftInputMode="adjustResize" for activity. Hope this useful for someone got the same problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With