2014-02-24 65 views
1

我有關於android中的編輯文本的問題。我設置編輯文本的背景和它的寬度是「WRAP_CONTENT」下面我code.But當用戶在其中輸入大量文字超出其實際大小的背景大小使EditText在固定長度的字符後水平滾動 - android

<EditText 
      android:id="@+id/edtEmail" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="15dp" 
      android:background="@drawable/text_field" 
      android:hint="@string/email_address" 
      android:inputType="textEmailAddress" 
      android:paddingEnd="20dp" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" 

      android:scrollHorizontally="true" 
      android:singleLine="true" /> 

所以我希望它能夠在30個字符後水平滾動。這樣我就不會超過背景的實際大小。任何幫助都是可以理解的。 在此先感謝

+0

我用這個已經檢查它在我的代碼 –

+0

現在固定寬度編輯文本到一些dps.you會得到你想要的。 – 2014-02-24 07:32:57

+0

但我無法修復編輯文本的寬度,因爲我的應用程序的模型應該是在中心水平。是否有方法來定義最大字符後,它成爲可滾動 –

回答

1

嘗試設置該屬性

android:maxEms="4" 

例如:這是我的EditText

<EditText 
    android:id="@+id/edittext_email_address" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:background="@drawable/bg_gray_edittext" 
    android:gravity="center" 
    android:hint="@string/hint_email_address" 
    android:imeOptions="actionNext" 
    android:inputType="textEmailAddress" 
    android:padding="5dp" 
    android:text="abcdefghijklmnopqrstuvwxyz1234567890qwerty1235" 
    android:textColor="@color/white" 
    android:maxEms="4" 
    android:textColorHint="@color/white70" 
    android:textSize="20sp" /> 

希望這個作品

+0

真的很好,感謝很多.. –

1

將此屬性設置爲您的編輯文本,它將在字符數超過寬度後滾動。

android:singleLine="true" 
+0

我已經使用過這個。 –