简体   繁体   中英

Custom android layout for Textfield element size

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM