gpt4 book ai didi

android - 转动模拟器后布局发生变化,但不是设备

转载 作者:太空狗 更新时间:2023-10-29 13:45:48 25 4
gpt4 key购买 nike

当方向为纵向时,我需要在 RecyclerView 中显示 2 列,当方向为 land 时,我需要显示 4 列。它在模拟器上工作正常。

enter image description here

它是纵向的 RecyclerView

开启模拟器:

enter image description here

如您所见,有刷新按钮。单击它后,我们会在屏幕上看到 4 列:

enter image description here

但是当我在手机上运行该项目时,没有刷新按钮,而且我在陆地方向看到了 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com