当方向为纵向时,我需要在 RecyclerView
中显示 2 列,当方向为 land
时,我需要显示 4 列。它在模拟器上工作正常。
它是纵向的 RecyclerView
。
开启模拟器:
如您所见,有刷新按钮。单击它后,我们会在屏幕上看到 4 列:
但是当我在手机上运行该项目时,没有刷新按钮,而且我在陆地方向看到了 2 列。
这是我的部分代码:
@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));
}
}
我在 list 中添加了这一行:
android:configChanges="orientation"
那么,问题是什么,我该如何解决?
最佳答案
你能像这样更改 onConfigurationChanged 方法中的代码块吗?也许可以提供帮助。
new GridLayoutManager(context, 1, GridLayoutManager.HORIZONTAL, false)
关于android - 转动模拟器后布局发生变化,但不是设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54921695/