我正在尝试使我的布局更加横向友好,我有一个常见的模式是添加LinearLayout一些按钮(例如OK |取消),只需设置一个值,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>
Run Code Online (Sandbox Code Playgroud)
注意:我知道我可以为横向创建一个新的布局文件并在那里做魔术.我想将专门的布局文件保持在最低限度,我希望这不需要它们.