android-设置Textview Edittext按钮

android-设置Textview Edittext按钮,第1张

概述我想在同一行中放置一个TextView,Edittext和一个按钮,但是我遇到的问题是该按钮没有正确地向左对齐,并且在小屏幕中,edittext填充了整个文本.小屏幕:大屏幕:我的编纂如下:<LinearLayoutandroid:id="@+id/layout1"android:layout_width="fill_parent"a

我想在同一行中放置一个TextVIEw,Edittext和一个按钮,但是我遇到的问题是该按钮没有正确地向左对齐,并且在小屏幕中,edittext填充了整个文本.

小屏幕:

大屏幕:

我的编纂如下:

<linearLayout        androID:ID="@+ID/layout1"        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:orIEntation="horizontal" >        <TextVIEw            androID:ID="@+ID/address_textvIEw"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:gravity="center"            androID:text="@string/address_textvIEw"            androID:textStyle="bold" />        <EditText            androID:ID="@+ID/address_edittext"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:hint="@string/address_textvIEw_hint"            androID:imeActionLabel="@string/search_button"            androID:imeOptions="actionDone"            androID:inputType="textCapWords"            androID:nextFocusDown="@ID/address_edittext"            androID:nextFocusUp="@ID/address_edittext"            androID:singleline="true" />        <relativeLayout        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:orIEntation="horizontal"        androID:gravity="right" >        <button            androID:ID="@+ID/go_button"            androID:layout_wIDth="50dp"            androID:layout_height="35dp"            androID:text="Go" />                </relativeLayout>    </linearLayout>

解决方法:

首先,许多人会告诉您提示是AndroID不需要标签的解决方案.我不在乎是否使用标签,但是它确实节省了空间,尤其是在较小的屏幕上.仅供参考.

现在,只有一个button的relativeLayout似乎没有用…我将其删除.您可以使用layout_weight,以便每个VIEw占用适当的空间量.确保设置layout_wIDth =“ 0dp”.所以看起来可能像

<linearLayout    androID:ID="@+ID/layout1"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"    androID:orIEntation="horizontal" >    <TextVIEw        androID:ID="@+ID/address_textvIEw"        androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        androID:layout_weight="2"        androID:gravity="center"        androID:text="@string/address_textvIEw"        androID:textStyle="bold" />    <EditText        androID:ID="@+ID/address_edittext"        androID:layout_wIDth="0dp"        androID:layout_height="wrap_content"        androID:layout_weight="3"        androID:hint="@string/address_textvIEw_hint"        androID:imeActionLabel="@string/search_button"        androID:imeOptions="actionDone"        androID:inputType="textCapWords"        androID:nextFocusDown="@ID/address_edittext"        androID:nextFocusUp="@ID/address_edittext"        androID:singleline="true" />    <button        androID:ID="@+ID/go_button"        androID:layout_wIDth="0dp"        androID:layout_height="35dp"        androID:layout_weight="1"        androID:text="Go" /></linearLayout>

在这里,我分别将2、3、1用作TextVIEw,EditText和button的权重.您可能需要更改这些设置才能准确获得所需的功能,但这应该可以帮助您开始.

总结

以上是内存溢出为你收集整理的android-设置Textview Edittext按钮全部内容,希望文章能够帮你解决android-设置Textview Edittext按钮所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1093176.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存