gpt4 book ai didi

android - 动态安卓 :orientation value for LinearLayout depending on device orientation without the need for 2 identical XML layouts

转载 作者:行者123 更新时间:2023-11-29 01:39:01 25 4
gpt4 key购买 nike

我有一个 XML 布局,在横向和纵向方向上工作得很好,但有一个异常(exception) - LinearLayout 中的两个按钮需要水平放置在横向设备方向上,垂直放置在纵向设备方向上。

我想知道是否有一些简单的方法可以只定义一个动态变量或一个可以放在 XML 布局文件中的字符串,而不必在 layout 中制作两个相同的副本> 和 layout-land 文件夹。

最佳答案

我最终以编程方式完成了它:

if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
// landscape
linearlayout.setOrientation(LinearLayout.HORIZONTAL);
} else {
// portrait
linearlayout.setOrientation(LinearLayout.VERTICAL);
}

Source

关于android - 动态安卓 :orientation value for LinearLayout depending on device orientation without the need for 2 identical XML layouts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25978511/

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