当软键盘消失/出现时,我希望我的布局重量发生变化。
喜欢
案例:disapper - >布局的重量= 6
案例:apper - >布局的重量= 10
所以我添加onlayoutChangeListener,但它的工作原理很奇怪。
if if(bottom
以及if(bottom> oldBottom)也是这样的。
总之,onLayoutChangeListener反向工作。relativelayout_wrap_content.addOnLayoutChangeListener(
new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right,
int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)
{
// TODO Auto-generated method stub
if(bottom<oldBottom && (bottom!=oldBottom) )
{
Toast.makeText(MainActivity.mainactivity_context, "bottom<oldBottom\n"+"bottom:"+bottom+"\noldBottom:"+oldBottom, Toast.LENGTH_LONG).show();
relativelayout_wrap_content.setLayoutParams(
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,0,6.0f));
}
else if(bottom>oldBottom && (bottom!=oldBottom) && isSoftKeyboardShown)
{
Toast.makeText(MainActivity.mainactivity_context, "bottom>oldBottom\n"+"bottom:"+bottom+"\noldBottom:"+oldBottom, Toast.LENGTH_LONG).show();
relativelayout_wrap_content.setLayoutParams(
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,0,10.0f));
}
}
});
edittext_free_reple.setOnFocusChangeListener(
new OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
// TODO Auto-generated method stub
if(hasFocus)
{
isSoftKeyboardShown = true;
relativelayout_wrap_content.setLayoutParams(
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,0,10.0f));
}
}
});
答案 0 :(得分:0)
屏幕左上角是(0,0)。因此,如果显示softKeyBoard,则底部必须小于oldBottom。那是(底部
if(bottom<oldBottom && (bottom!=oldBottom) )
{
//when the keyboard shown
}
else if(bottom>oldbottom)
{
//when the keyboard hidden
}