In landscape orientation I need to know if the navigation bar is at the right or left side of the screen so that I can apply paddings to a LinearLayout using WindowInsets to prevent the LinearLayout from overlapping the navigation bar.
Asked
Active
Viewed 1,165 times
0
-
If you're using window insets, it is already telling you where the insets are. – ianhanniballake Oct 30 '20 at 19:16
-
Might be https://stackoverflow.com/questions/21057035/detect-android-navigation-bar-orientation this link will help you. – Shubham Hupare Oct 31 '20 at 07:47
1 Answers
0
I ended up using OrientationEventListener
which returns the orientation of the device in form of degrees
,the value in orientation
depends on how the device is tilted,it ranges from 0-360.You might want to Toast
the values in real-time to know which degree would be reverse landscape and which would be landscape,it's hacky but gets the job done.In portrait it ranges from 0-50,in landscape it ranges from 55-120,in reverse landscape it's >250 but can be as low as 200 if orientation is rapidly changed.An orientation of -1 means that the device is lying flat on a surface.In reverse landscape the navigation bar
is at the right while in landscape it's at the left.
orientationListener = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
if(orientation>250){//reverse landscape
isReverse=true;
}
else {
isReverse=false;
}
}
};
if (orientationListener.canDetectOrientation()) {
orientationListener.enable();
} else {
orientationListener.disable();
}

Kenart
- 285
- 3
- 14