这将获得屏幕方向:
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getRotation();
Run Code Online (Sandbox Code Playgroud)
然后你可以这样检查:
if(orientation == Surface.ROTATION_90) {
// do something
} else if (orientation == Surface.ROTATION_270) {
// do something else
}
Run Code Online (Sandbox Code Playgroud)