我只需要检测导航栏是否位于屏幕右侧,如下图所示。感谢
答案 0 :(得分:2)
以下代码段可以提供帮助:
private boolean isNavigationBarRightOfContent(){
Rect outRect = new Rect();
ViewGroup decor = (ViewGroup) mActivity.getWindow().getDecorView();
decor.getWindowVisibleDisplayFrame(outRect);
DisplayMetrics dm = getResources().getDisplayMetrics();
return dm.widthPixels == outRect.bottom;
}
答案 1 :(得分:1)
如果导航栏处于横向模式,它将仅位于屏幕右侧。因此要检测到这一点,请使用getResources().getConfiguration().orientation
,如下所示:
String orientation = getResources().getConfiguration().orientation;
if(orientation.equals("ORIENTATION_LANDSCAPE"){
// screen in landscape, do what you want to do
}
答案 2 :(得分:0)
试试这个:
// retrieve the position of the DecorView
Rect visibleFrame = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(visibleFrame);
DisplayMetrics dm = getResources().getDisplayMetrics();
// check if the DecorView takes the whole screen vertically or horizontally
boolean isRightOfContent = dm.heightPixels == visibleFrame.bottom;
boolean isBelowContent = dm.widthPixels == visibleFrame.right;