新手Android程序員在這裏。我正在製作一個帶有EditText的xml佈局,EditText的寬度應該更改爲適合文本內部 - 文本可以由用戶或編程方式更改。我發現當文本超過4個字符時,EditText停止展開並將多餘的字符保持在屏幕外。 這裏是我的代碼:Android wrap_content不換行
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.appname.MainActivity" >
<EditText
android:id="@+id/textview1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_above="@+id/seekbar1"
android:layout_alignLeft="@+id/textview2"
android:ems="10"
android:imeActionLabel="Done"
android:imeOptions="actionDone"
android:inputType="phone"
android:text="@string/NaN" />
//Other objects...
</RelativeLayout>
閱讀WRAP_CONTENT的文檔,我還以爲它會做什麼,我想要的。我錯了嗎?謝謝您的幫助!
你已經寫了android:layout_height =「wrap_content」。據我所知,你想寬度可擴展,而不是高度... – fran 2014-10-02 22:24:13
你不能使用android:singleLine =「true」到你的edittext? – 2014-10-03 05:08:45