Android布局不显示控件
在阅读了一篇教程之后,我正在编写我的第一个android应用程序。我很兴奋,觉得很容易。然而,在添加了一个简单的编辑文本和一条helloworld消息之后,我跑了起来,希望看到一些东西,但什么也没有显示。无论是文本框还是默认的hello world。请问哪里出了问题?下面是我的布局,即activity_main.xmlAndroid布局不显示控件,android,Android,在阅读了一篇教程之后,我正在编写我的第一个android应用程序。我很兴奋,觉得很容易。然而,在添加了一个简单的编辑文本和一条helloworld消息之后,我跑了起来,希望看到一些东西,但什么也没有显示。无论是文本框还是默认的hello world。请问哪里出了问题?下面是我的布局,即activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t
<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:paddingLeft="16dp"
android:paddingRight="16dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textColor="#FF00FF00"/>
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textColor="#FF0000FF"
android:id="@+id/et_Text" />
</RelativeLayout>
因为您使用的是RelativeLayout,所以需要告诉Android每个控件之间的相对关系。更改布局,如下所示:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:id="@+id/textView1"
android:textColor="#FF00FF00"/>
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@+id/textView1"
android:textColor="#FF0000FF"
android:id="@+id/et_Text" />
这将告诉系统将编辑文本放置在文本视图下方。您能显示您在Java代码中实际使用此布局的位置吗?嗨,塔尼斯,谢谢,我更新了我的帖子。您的xml文件名是mainActivity.xml还是activity_main.xmlNo其activity_main。抱歉弄错了嘿,我试过了,对我有用
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:id="@+id/textView1"
android:textColor="#FF00FF00"/>
<EditText android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@+id/textView1"
android:textColor="#FF0000FF"
android:id="@+id/et_Text" />