Use getRotation()
:
WindowManager manager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
if (manager != null) {
Display display = manager.getDefaultDisplay();
int rotation = display.getRotation();
if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
//em LADNSCAPE atribuimos uma quantidade de colunas maior a sua recycler view
recyclerView.setLayoutManager(new GridLayoutManager(this, 4));
} else {
//em PORTRAIT uma quantidade menor
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
}
}
You can run this code on your onCreate
, when setting up your UI.
Link to class documentation: Display