Textfield 元素大小的自定义 Android 布局
在我的相对布局下,我放入一个 Textview
和一个 TextField
(它们都在左侧对齐)。
但是,TextField
无法拉伸到我想要的宽度(好吧,如果它接触到右侧而不是其他任何地方,它会一直拉伸)。
如何实现文本字段拉伸到任意长度?
Textfield
与EditText
相同。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1">
<TextView android:id="@+id/textItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="10dp"
android:background="#00000000"
android:textColor="#ffffffff"
android:textSize="22sp"
android:text="Settings"
android:enabled="false"
>
</TextView>
<RelativeLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/relativeLayout1" android:layout_weight="1.03">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:id="@+id/textView1" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_marginLeft="20dp" android:layout_marginTop="18dp"></TextView>
<EditText android:layout_width="wrap_content" android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_alignLeft="@+id/textView1" android:layout_marginTop="18dp">
<requestFocus></requestFocus>
</EditText>
</RelativeLayout>
</LinearLayout>
Under my relative layout, I put in a Textview
and then a TextField
(both of them are aligned on the left hand side).
However, the TextField
can not stretch to the width I want (well, it would stretch all the way if it touches the right hand side but not anywhere else).
How can I achieve that the Textfield stretches to any arbitrary length?
Textfield
is the same as EditText
.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1">
<TextView android:id="@+id/textItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="10dp"
android:background="#00000000"
android:textColor="#ffffffff"
android:textSize="22sp"
android:text="Settings"
android:enabled="false"
>
</TextView>
<RelativeLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/relativeLayout1" android:layout_weight="1.03">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:id="@+id/textView1" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_marginLeft="20dp" android:layout_marginTop="18dp"></TextView>
<EditText android:layout_width="wrap_content" android:id="@+id/editText1" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_alignLeft="@+id/textView1" android:layout_marginTop="18dp">
<requestFocus></requestFocus>
</EditText>
</RelativeLayout>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
机器人:layout_width =“50dp”。将值设置为您想要的任何大小。
android:layout_width="50dp". set the value to whatever size you want it to be.