Jonas Pedersen
Jonas Pedersen

Reputation: 951

Expand EditText width on input

I'm a rookie programmer, so it might be some quite basic stuff i'm asking - although i haven't been able to find an answer using a search engine.

Problem 1:

I need each of these EditTexts to expand their width on input. I tried adding android:inputType="textCapSentences" and setting width to "Wrap_content" in each of the views - however, it appears not to work, plus it removed the hint which is given.

Here's my code for it:

      <LinearLayout 
       android:id="@+id/namebar"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:orientation="horizontal"
       android:paddingRight="20.0dip"
       android:paddingLeft="20.0dip"
       android:paddingTop="20.0dip"
       android:layout_above="@+id/tavleframe"
       >
       <EditText
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:background="@drawable/tavle"
            android:gravity="center"
            android:hint="@string/name_text"
            android:textColor="#ffffffff"
            Imageview.Scaletype="fill_parent"
            android:inputType="textCapSentences"
            />

       <EditText
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:background="@drawable/tavle"
            android:gravity="center"
            android:hint="@string/name_text"
            android:textColor="#ffffffff"
            Imageview.Scaletype="fill_parent"
            android:inputType="textCapSentences"/>

       <EditText
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:background="@drawable/tavle"
            android:gravity="center"
            android:hint="@string/name_text"
            android:textColor="#ffffffff"
            Imageview.Scaletype="fill_parent"
            android:inputType="textCapSentences"/>

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:background="@drawable/tavle"
            android:gravity="center"
            android:hint="@string/name_text"
            android:textColor="#ffffffff"
            Imageview.Scaletype="fill_parent"
            android:inputType="textCapSentences"/>

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:background="@drawable/tavle"
            android:gravity="center"
            android:hint="@string/name_text"
            android:textColor="#ffffffff"
            Imageview.Scaletype="fill_parent"
            android:inputType="textCapSentences"/>                                            
   </LinearLayout>

Upvotes: 0

Views: 670

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234795

It would help to know what you mean by "it appears not to work", but I have an idea. You are setting the width to wrap_content, but you are also setting the layout_weight to 1. This will distribute any excess horizontal space in equal amounts to each EditText. Just remove the android:layout_weight attribute from each EditText.

I also don't understand what you mean by "it removed the hint which is given".

Upvotes: 1

Related Questions