因此,我开始深入 Android 世界,并尝试遵循此处的官方入门
指南:building-ui 。该教程看起来很简单,但我遇到了一些事情不太匹配的问题。
例如:
- 在教程中,他们说有一个默认创建的layout/main.xml 文件。我没有得到这个文件,而是得到了layout/my_first_activity.xml。这些文件的内容也不同。
这是为什么呢?我究竟做错了什么?文档是否旧? (我使用的是 Eclipse Juno
,并使用 Android 2.3 SDK
)。我尝试准确地格式化(复制教程中的代码),但是当我尝试运行该应用程序时,出现错误。
--
教程说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>
最佳答案
是的,文档有点旧。你说得对;它们是同一个文件,但名称不同。如果您感觉好一些,您可以安全地将其重命名为 main.xml。
您选择了默认创建“hello world” TextView 的设置,因此它会继续为您创建该 TextView。
如果需要,您可以将 RelativeLayout
替换为 LinearLayout
以按照教程进行操作。我认为该部分在新的 ADT 中不起作用。
关于java - 我的 res/layout/main.xml 文件在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11554439/