我使用以下main.xml
代码,但我只能看到一个编辑文本框
我需要帮助了解为什么会发生这种情况?我已经尝试了很多次,但我看不到正确的编辑框和所有其他组件
<LinearLayout 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"
tools:context=".MainActivity" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="ENTER THE PHONE NUMBER HERE" />
<EditText
android:id="@+id/txtPhoneNo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Message"
/>
<EditText
android:id="@+id/txtMessage"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:gravity="top"
/>
<Button
android:id="@+id/btnSendSMS"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send SMS"
/>
这是因为您没有为LinearLayout
设置方向,默认方向是水平的。由于您的所有视图宽度都设置为fill_parent
,因此没有其他的空间
你有几个选择。您可以设置
android:orientation="vertical"
在根LinearLayout
中,或者您可以更改这些视图的宽度
android:layout_width="wrap_content"
显然,还有其他方法,但这些是对最简单的修复方法
LinearLayout文档
另请注意:
FILL_PARENT(在API 8级及更高版本中重命名为MATCH_PARENT),这意味着视图希望与其父级(减去填充)一样大
布局参数
旁注
我看到您在xml中使用了硬编码字符串。Eclipse会警告您这一点,如果您不习惯使用strings.xml
文件夹和android:text="@string/string_name"
,将来可能会让您头疼
字符串
在LinearLayout上检查方向=垂直