gpt4 book ai didi

android - 为什么 EditText 没有扩展到 fill_parent

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:24:28 26 4
gpt4 key购买 nike

我已经编写了一个 XML 代码,我希望在其中扩展 EditText 以适应父宽度。花了这么多时间,我找不到扩展 EditText 的方法。

这是我的 XML:

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<TableRow
android:layout_marginLeft="10dp"
android:layout_marginBottom="15dip">
<TextView
android:text="Comment"
android:layout_width="match_parent"
android:textStyle="bold"
android:padding="3dip" />
</TableRow>

<TableRow
android:layout_marginLeft="10dp"
android:layout_marginBottom="15dip">
<EditText
android:id="@+id/EditText02"
android:layout_height="wrap_content"
android:lines="5"
android:gravity="top|left"
android:inputType="textMultiLine"
android:scrollHorizontally="false"
android:minWidth="10.0dip"
android:maxWidth="5.0dip"/>
</TableRow>

<TableRow
android:layout_marginLeft="10dp"
android:layout_marginBottom="15dip"
android:gravity="center">
<Button
android:id="@+id/cancel"
android:text="Next" />
</TableRow>
</TableLayout>
</LinearLayout>

我在这里做错了什么。请帮助我。

最佳答案

有点老了,但我相信我有一些要补充的。

我相信根据文档(在下面引用),layout_width 和 layout_height 是为所有 TableRow 子项预先确定的。

相反,layout_weight 可用于确定 TableRow 内元素的宽度/高度。也就是说,除非你想设置它的 android:ems 属性并根据它的字体大小给它一个宽度。

例如:

<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >

<EditText
android:id="@+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/place"
android:inputType="textPersonName" >

<requestFocus />
</EditText>

</TableRow>

这为我在 TableRow 中生成了一个全屏宽度的 EditText。

这是来自 documentation 的引述表格行:

The children of a TableRow do not need to specify the layout_width and layout_height attributes in the XML file. TableRow always enforces those values to be respectively MATCH_PARENT and WRAP_CONTENT.

问题是,正如我们所知,实际上并没有发生。我怀疑 layout_width 也收到“WRAP_CONTENT”。

关于android - 为什么 EditText 没有扩展到 fill_parent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11603751/

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