我试图使我的布局更适合横向屏幕,常见的方式是添加一个包含一些按钮 (如 确定|取消) 的 LinearLayout
,并设置一个 layout_weight
值,以便空间均匀分配。 问题在于,当你在手机或平板电脑上使用横向模式时,你会得到看起来荒谬的巨大按钮。我尝试在按钮和线性布局上设置maxWidth
,但没有效果。最简单的方法是什么?即设置视图的最大水平尺寸,使其不会扩展到整个宽度。我尝试了很多不同的方法,但没有任何一个行得通。
这里是一个示例布局:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="6dp"
android:paddingBottom="6dp">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:enabled="false"
android:textStyle="bold"
android:text="@string/button1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button2" />
</LinearLayout>
注意:我知道我可以为横屏创建一个新的布局文件并在那里进行更改。我希望尽量减少专门的布局文件数量,并且我希望这不需要它们。