我的res/layout/main.xml文件在哪里?

问题描述:

所以我开始潜入Android世界,并试图按照官方getting started指南从这里:building-ui。本教程似乎很简单,但我遇到的问题不太匹配。我的res/layout/main.xml文件在哪里?

例如:

  1. 在本教程中,他们说那里是一个的默认创建的布局/ main.xml中的文件。我没有得到这个文件,而是我得到了layout/my_first_activity.xml。这些文件的内容也不相同。

这是为什么?我究竟做错了什么?文档是否过时? (我正在使用Eclipse Juno,并使用Android 2.3 SDK)。我尝试格式化(从tutorals复制代码),但是当我尝试运行该应用程序时出现错误。

-

教程说的main.xml文件是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 
</LinearLayout> 
. 
. 
. 

我my_first_activity.xml看起来是这样的:

<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:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:padding="@dimen/padding_medium" 
     android:text="@string/hello_world" 
     tools:context=".MyFirstActivity" /> 

</RelativeLayout> 
+0

请问你能在这里发布你的logcat输出吗? – 2012-07-19 05:33:25

是的,文档有点旧了。你说得对;它们是同一个文件,名称不同。如果它让你感觉更好,你可以安全地将它重命名为main.xml。

您已选择默认创建“hello world”文本视图的设置,因此它继续为您创建TextView。

如果需要,您可以用LinearLayout替换RelativeLayout以遵循本教程。我不认为该部分适用于新的ADT。

似乎ADT(Android开发工具)是最近更新 - 请参阅有关更改的详细信息here。可能文档不会同时更新。 您提供的布局文件中的差异并不重要,因此请尝试使用my_first_activity.xml执行本教程的其他步骤。