So I started diving into the Android world and was trying to follow the official getting started guide from here: building-ui. The tutorial seems simple enough, but I’m running into issues where the things don’t quite match up.
For example:
- In the tutorial, they say there’s a layout/main.xml file that’s created by default. I don’t get this file and instead, I get layout/my_first_activity.xml. The contents of these files are different as well.
Why is this? What am I doing wrong? Is the documentation old? (I’m using Eclipse Juno, and use Android 2.3 SDK). I try to format (copy the code from the tutorals) exactly but when I try to run the app I get errors.
—
Tutorial says main.xml file is like this:
<?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 my_first_activity.xml looks like this:
<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>
Yeah, the documentation is a little old. You’ve got it right; they’re the same file, with different names. You can safely rename it to main.xml if it makes you feel better.
You’ve picked the setting that creates a “hello world” text view by default, so it went ahead and created that TextView for you.
If you want, you can replace the
RelativeLayoutwithLinearLayoutto follow the tutorial. I don’t think the part works in the new ADT.