android 设置布局宽度,android – 如何设置布局的最大宽度

处理您的情况的适当方法是创建一个单独的布局文件,以便在使用现有的手机文件时优化平板电脑的窗体视图。您可以通过创建单独的res / layout目录,其中包含屏幕尺寸和/或分辨率的限定符。

您可以阅读更多关于可用的资源限定词here.有很多选择在这里,我会留给你选择最适合你的应用程序,但这里是一个简单的例子:

我们假设你当前的布局文件是form.xml。

将您现有的布局文件放在res / layout / form.xml中。这将使其成为默认布局。

创建另一个文件并将其放在res / layout-large / form.xml中。此布局文件将用于物理屏幕尺寸> 〜5“(所有标准平板电脑)。为了处理您的问题,我修改了默认布局,以水平方式显示窗体,仅占屏幕宽度的60%

android:id="@+id/adlayout"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="horizontal"

android:gravity="center_horizontal"

android:weightSum="1" >

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="0.6"

android:stretchColumns="1" >

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="6dip"

android:text="Barcode Format" >

android:id="@+id/edit_barcode_format"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:padding="6dip" >

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="6dip"

android:text="Barcode Type" >

android:id="@+id/edit_barcode_type"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:padding="6dip" >

该更改使用LinearLayout的layout_weight和weightSum属性,该属性告诉表仅填充其父级的60%(layout_weight = 0.6)。这比设置最大宽度更有效,特别是当设备具有可变分辨率和宽高比时。

FYI,我还试图删除你在XML中所做的一切不必要的属性,只是创建杂乱(如多个xmlns:android声明)。其中一个更改是从TableLayout孩子中删除额外的layout_参数,因为TableLayout无论如何都忽略所有这些参数,并强制其子项使用某些约束。从文档:

The children of a TableLayout cannot specify the layout_width attribute. Width is always MATCH_PARENT. However, the layout_height attribute can be defined by a child; default value is WRAP_CONTENT. If the child is a TableRow, then the height is always WRAP_CONTENT.

您可以阅读有关TableLayout in the SDK docs的更多信息。

HTH

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值