gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 22:20:45 40 4
gpt4 key购买 nike

经过大量谷歌搜索后,我无法找到解决此问题的方法。我有这个布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/adlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:layout_weight="1"
>

<TableRow android:id="@+id/tableRow1" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:padding="6dip" android:text="@string/barcode_format" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:padding="6dip" android:layout_width="fill_parent" android:id="@+id/edit_barcode_format" android:layout_height="wrap_content"></EditText>
</TableRow>
<TableRow android:id="@+id/tableRow1" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:padding="6dip" android:text="@string/barcode_type" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:padding="6dip" android:layout_width="fill_parent" android:id="@+id/edit_barcode_type" android:layout_height="wrap_content"></EditText>
</TableRow>
</TableLayout>


</LinearLayout>

表格布局定义了一个表格。在手机上看起来不错,但在平板电脑上,edittext View 看起来太大了。我想为布局设置最大宽度,并将表单居中绘制。

最佳答案

按照@Devunwired 的建议保留不同的布局文件是正确的,但是,它会增加项目的复杂性(您必须维护多个文件,以防设计师重新设计 View 布局)。

如果您只需要更改按钮的宽度,我建议您执行以下操作。在 layout 文件夹中保留一个 xml 文件,并为其赋值

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

values-w600dp/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>
</resources>

编辑:注意文件夹是 values-w600dp 而不是 values-600dp

关于android - 如何设置布局的最大宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8873059/

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