2014-02-26 34 views
2

我的編輯文字在輸入文字時自動延伸,不知道我做了什麼錯誤,請檢查我的屏幕截圖,以確定我的問題是什麼,幫助我找到解決方案。提前致謝。我的編輯文字在輸入文字時得到延長

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="50dip" 
     android:gravity="center" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" > 

      <EditText 
       android:id="@+id/oldpass" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/selectdate" 
       android:ems="10" 
       android:hint="@string/oldpass" 
       android:inputType="textPassword" 
       android:paddingLeft="5dip" > 
      </EditText> 
     </LinearLayout> 


    </LinearLayout> 

檢查我的屏幕截圖如何它的延伸,同時打字enter image description here

回答

2

也正是由於這個佈局定義:android:layout_width="wrap_content"

你基本上是告訴你EditText應該適合的內容。這意味着它會有一個默認的大小,但是一旦你輸入並擴大它的大小,它將根據它裏面的文本進行擴展。

您可能想要使用android:layout_width="match_parent"將其安裝到屏幕上,或使用android:layout_weight來使其與其他佈局項目成比例。

+0

感謝它在給出版面重量後的工作。 – Madhu

+1

很高興幫助。無論是出於信譽還是反饋的目的,一旦你獲得了你想要的解決方案,接受最能幫助你的答案。 – nKn

+0

+1爲您的答案和您的評論「答案,幫助你最」。 – Aravin

3

你的身高和體重都Wrap_content,因爲它調整後,你給

變化,爲固定dp長度

文本的長度
android:layout_width="150dp" 
android:layout_height="wrap_content" 
+0

我需要集中我的EditText,如果我用包的內容沒有正確對齊。 – Madhu

+0

使用android:重力來對齊editText – Nambi

+1

這個答案是正確的,你所要做的就是爲edittext分配合適的重力值 – goonerDroid

0

試試這個

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:gravity="center" > 

     <EditText 
      android:id="@+id/oldpass" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/selectdate" 
      android:ems="10" 
      android:hint="@string/oldpass" 
      android:inputType="textPassword" 
      android:paddingLeft="5dip" > 
     </EditText> 
    </LinearLayout> 
2

設置WEIGHT property你的edittext不會擴展。

android:layout_width="0dp" 
android:layout_weight="1" 
0

我相信你的問題是你設置EditTex噸的layout_widthwrap_content

相關問題