Textfield 元素大小的自定义 Android 布局

发布于 2024-12-26 10:59:37 字数 1716 浏览 2 评论 0原文

在我的相对布局下,我放入一个 Textview 和一个 TextField (它们都在左侧对齐)。

但是,TextField 无法拉伸到我想要的宽度(好吧,如果它接触到右侧而不是其他任何地方,它会一直拉伸)。

如何实现文本字段拉伸到任意长度?

TextfieldEditText 相同。

<?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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微暖i 2025-01-02 10:59:37

机器人:layout_width =“50dp”。将值设置为您想要的任何大小。

android:layout_width="50dp". set the value to whatever size you want it to be.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文