【发布时间】:2014-10-02 21:51:57
【问题描述】:
这里是新手 Android 程序员。我正在制作一个带有 EditText 的 xml 布局,它的宽度应该改变以适合里面的文本——文本可以由用户或以编程方式更改。我发现当文本超过 4 个字符时,EditText 停止扩展并将多余的字符保持在屏幕外。 这是我的代码:
<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"。据我了解,您想要可扩展的宽度,而不是高度......
-
你不能使用 android:singleLine="true" 来编辑文本吗?