华为的一些手机的屏幕上的虚拟按键是可以显示或者隐藏的,因此在布局适配的时候就要考虑到这个问题,要不然当虚拟按键被隐藏后界面的布局就会出现问题,下面给出一种解决方法,(原文来自:安卓适配碰到的一些问题)
因为虚拟按键的打开会涉及到view的重绘,因此可以重写根layout中的onLayout方法来实现。假设根layout是FrameLayout
public class RootLayout extends FrameLayout{
public RootLayout(Context context,AttributeSet attrs){
super(context,attrs);
}
@Override
protected void onLayout(boolean change,int left,int top,int right,int bottom){
super.onLayout(change,left,top,right,bottom);
int tempWindowHeight = Util.getWindowManager().getDefaultDisplay() - Util.getStatusBarHeight(getContext());
//Util.windowHeight为事先缓存的高度
if(tempWindowHeight != Util.windowHeight){
Util.windowHeight = tempWindowHeight;
Util.windowWidth = Util.getWindowManager().getDefaultDisplay().getWidth();
}
}
}