The Eclipse project wizard generates a LinearLayout automatically, in the form of the res/layout/main.xml
file, and inflates it for us from the onCreate()
callback with the setContentView(R.layout.main)
statement. Here we will create two, slightly different layouts and switch between them with a button.
We will begin this task by editing our main layout file, so start a new Android project in Eclipse and open the res/layout
folder.
Open and edit the
res/layout/main.xml
file so that it matches the following code:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This layout is vertical." /> <Button android:text="Click for a horizontal...