gpt4 book ai didi

android - 在一行中对齐和调整textview和edittext的宽度

转载 作者:行者123 更新时间:2023-11-29 19:12:28 26 4
gpt4 key购买 nike

我有一个 TextView 和 EditText,它们需要以适当的跨度对齐成一行。

在当前布局中,EditText 是对齐的,但看起来缩小了,没有占用剩余宽度

enter image description here

XML:

 <TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:style="@style/AppTheme"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp">

<TableRow>
<TextView
style="@style/AppTheme.DetailInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Password:" />
<EditText
style="@style/AppTheme.TextBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:maxLines="1"
android:text= "@={profile.password}"/>
</TableRow>
</TableLayout>

最佳答案

如果想让EditText填充剩余的空间,应该设置它的layout_width = "0dp"和layout_weight = "1"。见:

https://developer.android.com/guide/topics/ui/layout/linear.html#Weight

"例如,如果有三个文本域,其中两个声明权重为1,而另一个没有赋予权重,则第三个没有权重的文本域不会增长,只会占据其内容所需的区域”

编辑:如果您希望编辑文本的开头对齐,您应该对所有 TextView 应用相同的权重,并对所有编辑文本应用相同的权重。原始答案将简单地填充剩余空间,而不保持编辑文本的开头对齐。

关于android - 在一行中对齐和调整textview和edittext的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44835101/

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