本文共 1803 字,大约阅读时间需要 6 分钟。
最后,我找到了我的问题的解决方法,所以我想分享给某人可能会在将来遇到同样的问题.我的布局简要描述如下:
//all stuff controls:editview,textview,....
我创建自定义类myRelativeLayout扩展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;
}
}
在我的活动中,我只是为myRelativeLayout设置setLayoutChangeListener以在软键盘显示时隐藏底栏并在软键盘隐藏时显示底栏:
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.
}
});
不要忘记为活动设置android:windowSoftInputMode =“adjustResize”.希望这对有人遇到同样问题很有用.
转载地址:https://blog.csdn.net/weixin_33960567/article/details/117350601 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!