美文网首页Android知识
Android计算底部的虚拟键的高度

Android计算底部的虚拟键的高度

作者: mianbaocheng | 来源:发表于2016-11-02 15:08 被阅读0次

1.获取不含有虚拟键的高度

float heightWithOutKey = getWindowManager().getDefaultDisplay.getHeight();

2.获取含有虚拟键的高度

float heightWithKey;

Display display  = getWidnowManager().getDefaultDisplay();

DisplayMetrics metrics = new DisplayMetrics();

Class c;

try{

c = Class.forName("android.view.Display");

 Method method = c.getMethod("getRealMetrics",DisplayMetrics.class);

 method.invoke(display,metrics);

 heightWithKey = metrics.heightPixels;

}catch(ClassNotFoundException ex){

    ex.printStackTrace();

}catch(InvocationTargetException ex){

  ex.printStackTrace();

}catch(IllegalAccessException ex){

    ex.printStackTrace();

}

3.计算虚拟键的高度

float keyHeight = heightWithKey-heightWithOutKey;

相关文章

网友评论

    本文标题:Android计算底部的虚拟键的高度

    本文链接:https://www.haomeiwen.com/subject/pkyvuttx.html