gpt4 book ai didi

android - 如何在 LinearLayout 上设置最大宽度,使其不会在横向模式下拉伸(stretch)?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:37:43 33 4
gpt4 key购买 nike

我的应用程序在纵向模式下看起来不错,但在横向模式下会拉伸(stretch)并且看起来很糟糕。我知道我可以为横向制作一个单独的布局,但我宁愿只设置我的根元素的最大宽度,这样横向模式只会在两侧产生一些空白。有办法做到这一点吗?

最佳答案

保留不同的布局文件是一个正确的解决方案,但它会增加项目的复杂性(您必须维护多个文件,以防设计人员重新设计 View 布局)。

如果您只需要改变 LinearLayout 的宽度,您可以执行以下操作。在layout文件夹中保留一个xml文件,并赋值为

<LinearLayout
style="@style/width_match_parent_max_200"
android:layout_height="wrap_content">

然后,在您的 values-600dp/styles.xml 中写入:

<resources>
<style name="width_match_parent_max_200">
<item name="android:layout_width">200dp</item>
</style>
</resources>

在你的 values/styles.xml 中:

<resources>
<style name="width_match_parent_max_200">
<item name="android:layout_width">match_parent</item>
</style>

关于android - 如何在 LinearLayout 上设置最大宽度,使其不会在横向模式下拉伸(stretch)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25574065/

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