Use the 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 configuring your UI.
Link to the class documentation: Display
Add the question to the layout of Recyclerview items.
– ramaral