只有 textView1 出现在屏幕上,按钮和编辑文本框没有出现。请检查我的代码。我是 android 开发的新手。我认为 edittext 和按钮的位置不正确。
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textView1" />
<EditText
android:id="@+id/edit_message"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="@string/edit_message"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edit_message"
android:layout_marginTop="49dp"
android:layout_toRightOf="@+id/edit_message"
android:onClick="sendMessage"
android:text="@string/button_send" />
</RelativeLayout>
最佳答案
RelativeLayout
没有 orientation
属性...删除它。另外,我认为如果将 marginTop
属性放在 below
其他 Views
中,您希望删除它们。您可能想改用 padding
。我不确定您是否可以位于同一 view
的右侧和下方,但这可能有效。这就是我目前所看到的一切
注意
fill_parent
已删除。现在可以使用,但您最好习惯使用 match_parent
根据我给出的建议,我得到了你的代码。见下文。请注意,高度
为 10dp,您可能看不到它,因为它不是很大
<?xml version="1.0" encoding="utf-8"?>
<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" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textView1" />
<EditText
android:id="@+id/edit_message"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:ems="10"
android:hint="edit_message"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edit_message"
android:onClick="sendMessage"
android:text="button_send" />
</RelativeLayout>
关于android - 相对布局字段的放置不当,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16113010/