3

I need to show 2 columns in RecyclerView when the orientation is portrait and 4 columns when orientation is land. It works correct on the emulator.

enter image description here

It's RecyclerView in portrait orientation.

Turning the emulator:

enter image description here

As you can see, there is refresh button. And after clicking on it we see 4 columns on screen:

enter image description here

But when I run the project on my mobile phone, there is no refresh button and I see 2 columns in land orientation.

Here's a part of my code:

@Override
public void onConfigurationChanged(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
        previewImages.setLayoutManager(new GridLayoutManager(this, 4));
    }
    else {
        previewImages.setLayoutManager(new GridLayoutManager(this, 2));
    }
}

And I added this line to manifest:

android:configChanges="orientation"

So, what's the problem and how can I solve it?

Sergei Mikhailovskii
  • 2,100
  • 2
  • 21
  • 43

1 Answers1

1

can you change your code block in onConfigurationChanged method like this. maybe can help.

new GridLayoutManager(context, 1, GridLayoutManager.HORIZONTAL, false)
ozanurkan
  • 399
  • 4
  • 13