【问题标题】:Where is my res/layout/main.xml file?我的 res/layout/main.xml 文件在哪里?
【发布时间】:2012-07-18 06:14:07
【问题描述】:

所以我开始潜入 Android 世界,并试图从这里遵循官方的 getting started 指南:building-ui。该教程看起来很简单,但我遇到了一些不完全匹配的问题。

例如:

  1. 在教程中,他们说默认创建了一个 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>

【问题讨论】:

  • 请问你能在这里发布你的 logcat 输出吗?

标签: java android xml android-layout android-activity


【解决方案1】:

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

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

如果您愿意,可以将RelativeLayout 替换为LinearLayout 以按照教程进行操作。我认为这部分在新的 ADT 中不起作用。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-06
      • 1970-01-01
      • 1970-01-01
      • 2010-12-13
      相关资源
      最近更新 更多