Android Eclipse: Development for the Android SDK. Android: Installing the Eclipse plugin Creating an eclipse project for android

In the Eclipse IDE, you can manage, edit, compile, run, and debug applications. The Eclipse ADT Plugin provides additional tools for users to use to develop Android applications. You can also use the ADT Plugin to manage different versions of the Android platform. This is required in the case of developing applications intended for various devices on which different versions are installed operating system Android. After starting the Eclipse environment for the first time, the Welcome tab appears:

This tab contains a number of icon links, clicking on which will take you to the appropriate sections.
Click the Workbench button to display perspective Java Development, in which Android application development begins. Eclipse supports application development in several programming languages. Each installed Eclipse toolbox is presented with a separate
development perspective.

Creating a new project
To start Android programming in Eclipse, execute the commands File-> NewProject ... to display the New Project dialog

This window can also be displayed using the New drop-down list on the toolbar.

Expand the Android node, select the Android Application Project option, and click the Next> button. The New Android Project dialog will appear on the screen.

Project Is a group of related files, such as code files and images, that form an application. In the New Project dialog, you can create a project from scratch, or use existing source code (for example, code from a book or examples provided with the Android SDK).

By the way, the New Android Application window has changed a lot, starting with the name and ending with the content. So we'll figure it out in the course of the play.
And so let's go! Fill in the fields as shown in the screenshot



Application Name- this is the name that will be displayed in the PlayStore, as well as in the application manager on the device on which the application will be installed.

Project Name- the name of the project used only in Eclipse. Must be unique in the production environment. Usually it is the same as the Application Name, but I made it different to make it clearer where the name will be displayed.

Package Name- this name MUST BE THE UNIQUE IDENTIFIER of your application. That is, you must be sure that no one will name their application like that anymore. And this name must remain the same throughout life cycle applications (versions of the application may change, but the name must remain the same).

Minimun Required SKD- the minimum Android version required for your application to function. This essentially means the minimum SDK version that is required for the application to function properly. And besides, Android simply will not allow installing an application if the device has an Android version whose API number is lower than that specified in this parameter.

Target SDK- the target or maximum version of Android on which the application will work for sure and has been tested. It is recommended to set this parameter as high as possible.

Compile SDK- the version of the SDK you installed with which the application will be compiled.

Theme- application theme.
Basically, detailed description all these points are in the bourgeois language and are available when you hover the mouse over a blue icon with a letter i.

And so click Next and see the following window

We remove the daw from Create custom launcher icon we press Next


Select Blank Activity and click Next and see the following window

We fill in as on the screen and click Finish and see the perspective of the development of the Java project

In yellow, I highlighted what is worth paying special attention to, so that it becomes clear where which names are stuck. Next, expand the node, then the layout node and double-click on main.xml and lo and behold! see how our application will look! By clicking on main.xml, we invoke the ADT Visual Layout Editor. It can be used to create graphical interface user by dragging GUI components such as Buttons, TextViews, ImageViews, etc. into the application window.

We will slightly reconfigure our environment so that everything is better seen

In the project node, the contents of a project are organized in various files and folders, including:
src- the folder containing the source files of the Java project;
gen- folder containing Java files generated by the IDE;
Android 2.3.3- folder containing the Android framework version selected when creating the application;
res- the folder that contains the resource files associated with the application, such as GUI layouts and images used in the application.
we will consider other daddies later.
When you create an Android application using Eclipse, the layout of the user interface is stored in an XML file, which is named main.xml by default. By defining GUI elements in an XML file, you can easily decouple application logic from its presentation. Layout files are application resources and are stored in the res folder of the project. The GUI layouts are located in a subfolder of the layout folder.
To view the XML content of the file, select the tab with the name of the layout file (in this case, main.xml). To go back to the Visual Layout Editor view, select the Graphical Layout tab.
In principle, this application can already be launched for execution. I ran it using Genymotion as it is much faster than the Android emulator from the SDK and even Intel.

Useful video on this topic

And so we continue to experiment with our first project.

Deleting and recreating the main.xml file
In the process of building the application for this chapter, a new layout file, RelativeLayout, will be used instead of the default main.xml file (this file defines the relative position of the components). To replace the default main.xml file, follow these steps:
1) Make sure the main.xml file is closed, then right-click on it (in the / res / layout folder of the project) and select Delete to delete the file.
2) In the Android node, select the Android XML Layout File option and click Next

4) Make sure that the file is created in the / res / layout directory

And click Finish and get into the already familiar window



Setting screen size and resolution in Visual Layout Editor
Since the Android operating system can run on many different devices, Visual Layout Editor comes with a number of different device configurations, representing different screen sizes and resolutions. These settings are selected from the Device Configurations drop-down list.

If the default configurations do not match the device for which the application is being developed, you can create your own device configuration “from scratch” or by copying and changing one of the existing configurations.
To create the examples in this book, we used a basic Samsung Nexus S test device, which is equipped with a 4-inch 480x800-pixel (WVGA) screen. It is recommended to develop a scalable Android GUI library that will correctly render images on the screens of various devices. Due to the scalability feature, the Visual Layout Editor design area does not need to match the physical device screens. It is enough to choose a similar device configuration.

Image and screen sizes and resolutions

Because Android device screens come in different sizes, resolutions, and screen pixel densities (expressed in dots per inch or DPI), images (and other resources) are supported that are selected by the operating system based on the device's screen pixel density. Therefore, in the folder res there are four subfolders of the project:
drawable-xhdpi(ultra high density)
drawable-hdpi(high density)
drawable-mdpi(medium density)
drawable-ldpi(low density)

Pixel densities of Android devices

xhdpi Ultra-high density - approx. 320 dpi
hdpi High density - approx. 240 dpi
mdpi Average density - approximately 160 dpi
ldpi Low density - approx. 120 dpi
nodpi No resource scaling regardless of screen density
Step 1. Adding images to the project
For of this application add the Deitel bug (bug.png) and Android logo (android.png) images to the project. These images are located in the images folder along with the book examples. To add images to your project, follow these steps:
1. In the Package Explorer window, open the res project folder.
2. Find and open the images folder, which is among the examples of the book, then drag the images into the folder located in the drawable-hdpi subfolder of the res folder.


Images can now be used in the application.

Step 2. Changing the Id property of the RelativeLayout
Using the Properties window, you can configure the properties of a selected layout or component without directly editing the XML. If the Properties window is not visible, double-click the RelativeLayout item in the Outline window to display it.

Select the RelativeLayout component, then scroll in the Properties window, select the Id property and assign a value to it:

@ + id / welcomeRelativeLayout

The name of each object is determined using its Id property. This property can be used to access and modify a component without the need for
know the exact location of the component in the XML. As you will see later, the Id property can also be used to specify the relative positioning of components in the RelativeLayout.

Symbol + in construction @ + id defines the creation of a new identifier (variable name), which is specified to the right of the symbol /

Step 3. Setting the Background property of the RelativeLayout to a value
By default, white is selected as the background color of the layout (in our case), but it can be changed (for example, to yellow). Any color is the result of mixing red, blue and green components, which are called RGB components. Each of these components can take an integer value in the range from 0 to 255. The first component specifies the amount of red in the overall color, the second - the amount of green, and the third - the amount of blue. When working in the integrated development environment (IDE), hexadecimal format is used to define the color. That is, RGB components are represented as values ​​in the range 00 – FF.
To change the background color, find the Background property in the Properties window and set it to #FFFF33

The # RRGGBB format is in pairs hexadecimal numbers which represent red, green, and blue, respectively. Android also supports alpha values ​​(transparency), which range from 0-255. A value of 0 is fully transparent, and a value of 255 is fully opaque. If you plan to use alpha values, specify the color in #AARRGGBB format, where the first two hexadecimal digits correspond to the alpha value.
If both digits of each color component are the same, you can use the # RGB or #ARGB format. For example, # FFF is treated as #FFFFFF.

Step 4. Adding the TextView component
In this step, we'll add a TextView component to the UI. In the Form Widgets list on the left side of the Visual Layout Editor, find the TextView component and drag it to the design area



After adding a new component to the user interface, it is automatically selected and its properties are displayed in the Properties window.

Step 5. Setting the Text property of the TextView component using string resources

According to the Android documentation for app resources (developer.android.com/guide/topics/resources/index.html) it is considered good practice to store strings, string arrays, images, colors, font sizes, dimensions, and other app resources in a way that can be use separately from the application code. For example, after externalizing color values, all components using the same color can be recolored by simply changing the color value in the central resource file.
If you need to localize your applications by creating versions in several different languages, keep the strings separate from the application code. As a result, you will be able to easily change these lines in the future. The res folder of the project contains the values ​​subfolder, which contains the strings.xml file. This file is used to store strings. To generate localized strings for other languages, create separate values ​​folders for each language you use.
For example, the values-fr folder might contain a strings.xml file for French, and the values-es folder might contain a strings.xml file for Spanish. You can also form the names of these folders taking into account the information about the region. For example, the values-en-US folder might contain the strings.xml file for American English, and the values-en-GB folder might contain the strings.xml file for the UK English dialect.
For more information on localization, refer to the resources:

Developer.android.com/guide/topics/resources/;
providing-resources.html.AlternativeResources;
developer.android.com/guide/topics/resources/localization.html.

To set the value of the Text property of the TextView component, create a new string resource in the strings.xml file.

1. Select the TextView component.
2. In the Properties window, find the Text property, click the default, then click the ellipsis button. This button is on the right
part of the property value field and displays the Resource Chooser dialog box.

3. In the Resource Chooser dialog box, click the New String… button to display the Create New Android String dialog box.
Android string)

4. Complete the String and New R.string fields, then click OK to hide the Create New Android String dialog box and return to the Resource Chooser window.

5. The new string resource welcome is automatically selected. Click the OK button to select this resource.

After completing the above steps, the Text property appears in the Properties window. The @string entry indicates that an existing string resource can be selected in the strings.xml file, and the name welcome indicates that the string resource is currently selected.

The main advantage of defining string values ​​is that it makes it easier to localize the application by creating additional
XML resource files for other languages. Each file uses the same name in the New R.string field and maintains an internationalized string in the String field. Android can then select the appropriate resource file based on the preferred language of the device user. More information on localization can be found at developer.android.com/guide/topics/resources/localization.html.

Step 6. Setting the Text size and Padding top properties of the TextView component - pixels independent of density and scaling

Sizes of GUI components and text on android screen can be defined using different units of measure.
Documentation describing the various screen sizes can be found at developer.android.com/guide/practices/screens_support.html and recommends using density-independent pixels for sizing GUI components and other on-screen elements, and using font sizes set using pixels independent of scaling.

Density-independent pixel dimensions (dp or dip) allow the Android platform to automatically scale the GUI based on the pixel density of the physical device's screen.
Density-independent pixel size is equivalent to a physical pixel on a 160 dpi (dots per inch) screen. On a screen with a resolution
A 240 dpi pixel size independent of density will be scaled by a factor of 240/160 (i.e. 1.5). Thus, a component that is 100 pixels independent of density will be scaled to 150 physical pixels on such a screen. On a 120 dpi screen, each density independent pixel is scaled by a factor of 120/160 (that is, 0.75). This means that 100 pixels independent of the density will turn into 75 physical pixels on such a screen. Scale-independent pixels are scaled in the same way as density-independent pixels, but their scale also depends on the user's preferred font size.
Now let's increase the font size for the TextView component and add a little padding above the TextView component.
1. To change the font size, select the TextView component and then set the Text size property to 40sp.
2. To increase the margin between the top edge of the layout and the TextView, select the Layout margin top property in the Misc section of the Properties window.
and give it a value of 10dp.



Step 7. Setting additional properties of the TextView component
Configure additional properties of the TextView component as follows:
1. Set the Id property to @ + id / welcomeTextView.
2. Set the Text color property to # 00F (blue).
3. Set the Text style property to bold. To do this, click in the Valu field of this property, then click the ellipsis button to display a dialog box where you can select a font style. Check the bold box, then click the OK button to select a text style.
4. Set the Gravity property to center to center the TextView text when it is spread over multiple lines. For execution
this operation, click in the Value field of that property, then click the ellipsis button to display the property settings dialog box.
Gravity



Step 8. Displaying Android Logos and Deitel Bug Using ImageViews Components
1. Drag the ImageView component located in the Images & Media category of the Visual Layout Editor palette into the Outline window. A new ImageView component appears below the welcomeTextView node.





2. Set the Id property of the ImageView component to @ + id / droidImageView. The Outline window displays the name of the droidImageView object.

3. Set the droidImageView's Layout center horizontal property to true to center the ImageView component within the layout.

4. Set the Content Description field to @ string / droidPic

5. Do the same for the bug.png drawing. Set the Id property of the component to @ + id / bugImageView.

Well, let's launch our first application :)

Today we have a task: to configure Eclipse for Android development.

The following things will be required:

  1. Eclipse (I used Classic)
  2. Android Developer Tools (ADT)
  3. Android SDK

The first thing you need is a development environment (IDE). On Android, this is Eclipse. You can download it from the official website: http://www.eclipse.org/downloads/ (Download in accordance with the bitness of the operating system installed on the computer). It's great that Eclipse is available for Windows, Linux, and Mac. It's also free. Eclipse is not installed - it is enough to download and unpack it to disk in a separate folder (it is better to create a folder somewhere without Russian letters in the name)

The JDK is required for Eclipse and Java to work. You can download it on the Oracle website. The JRE version will suffice.

A window will open in which you will need to specify the url to the server where the package is located. Google has the following address: https://dl-ssl.google.com/android/eclipse/, then you need to check all the items in Developer Tools and click Next

The wizard will install ADT. After that, you will need to restart Eclipse.

Next, you need to go and download the Android SDK. This can be done on the official website. You need to download bin - it's more convenient. After that, you need to link the SDK and Eclipse:

Go to Window -> Preferencess -> Android

Specify the location where the SDK was installed in the SDK Location text box. By default, this is: C: \ Program Files (x86) \ Android \ android-sdk

The last step is to update this very SDK. Go to Window -> Android SDK Manager. A window like this will open (I already have everything installed):

In an amicable way, here you can select all packages and click the Install packages button. And you can go and drink coffee. The process will take over an hour. I was asked for a password for some packages not from Google - we refuse and skip - it will still work.

Problem

You want to use the Eclipse environment to develop your application for the Android platform.

Solution

Install the Eclipse environment and the AndMore plug-in. Then create your project and start writing your application. Build it and test it with an emulator in Eclipse.

Discussion

Before you can start building your application with Eclipse, you need to install three items:

  • Eclipse IDE
  • Android SDK
  • AndMore module

For details on how to install these items, see.

After you have done this, create a new Android project using the File → New menu, and you will see a screen like the one in Fig. 1.

Select the SDK version for the target device (Figure 3). Version 4.0 covers almost all devices in use today; later versions provide even more options. You decide!

Rice. 1.

Rice. 2.

Rice. 3.

In fig. 4 shows the project structure expanded in the project pane on the right. It also shows to what extent you can use Eclipse autocomplete on Android platform - I added a gravity attribute for the label, and Eclipse environment offers a complete list of possible attribute values. I chose central-horizontal, so the shortcut should be centered when the application starts.

Rice. 4.

Setting the gravity to center_ vertical in the LinearLayout and center_horizontal in the TextView will center the text both vertically and horizontally. Listing 1 shows the corresponding main.xml layout file (located in the res / layout directory).

Listing 1. File HelloWorld. java

As always, when you save the source file, the Eclipse environment generates a compiled version. In an Android project, it also creates a compiled ARC package that is ready to run, so you only need to run it. Right click on the project and select Run As → Android Application (Figure 5).

Due to the fact that some people cannot start my projects, and after talking with them, I realized that the problem is not in the code, but in the assembly of the Eclipse + Android SDK, I decided to write how to put this beauty, and bring it to mind.

Installing Eclipse and Android SDK

  • Download the Android SDK for your platform (Windows, Mac OS X, or Linux).
  • Unpack the downloaded files to any memory location on your hard drive (on my Windows it is D: \ eclipse \).
  • If Eclipse is already installed, download and install the Eclipse IDE for Java Developers package. For programming, Google recommends using Eclipse 3.5 (Galileo).
  • Start Eclipse and select Help-> Install New Software.
  • Click on Add in the Available Software window.
  • Enter Android Development Tools in the box Name and https://dl-ssl.google.com/android/eclipse/ in the box Location.
  • Click on OK and check Developer Tools in the list of available software. This will install Android Development Tools and DDMS, a debugging tool for Android. If you have any problems with installing ADT, then use the old version of ADT 15.0. Upgrade to version 15.0

    • Click on Next and Finish to install the plugin. You need to restart Eclipse once after installation.
    • After restarting Eclipse select Window-> Preferences and you will see Android in the list of categories.
    • Now you need to tell Eclipse where the installed Android SDK is located. Click on Android, then Browse to select the location of the unpacked SDK files. For example, C: \ Program Files \ android \ android-sdk

  • Android platform targeting

    Before you start writing Android apps, you need to download the Android SDK. Each platform has its own version of the Android SDK that is installed on users' devices. There are two platforms for Android 1.5 and higher: Android Open Source Project and Google.

    Android Open Source Project- open source platform, but does not include Google extensions, such as Google Maps. If you don't want to use the Google API, the functionality google maps will be unavailable for your application. Unless you have a specific reason to do this, I would recommend that you target one of Google's platforms, as this will allow you to use Google's own extensions.

    • Please select Window-> Android SDK Manager.
    • Click on Available Packages in the left column and check the repository to show a list of available Android platforms.
    • You can select platforms to download from the list, or leave all checked to download all available platforms. When finished, click Install Selected and follow the installation instructions.

    Once everything has been downloaded successfully, you are ready to start developing for Android.

    Creating a new Android project

    The Eclipse New Project Wizard guides you through creating Android app by generating files and code, ready to run, to the right of the block. it quick way make sure it works and a good starting point when starting application development:

    After clicking Finish Eclipse will create a new Android project ready to run. Remember you told Eclipse to generate an Activity named MyFirstAndroidProjectActivity ? This is the code that Android actually uses to launch the application. The generated code will be displayed as a simple ‘Hello World’ message.

    Packages

    The package name is the identifier for your application. When is the time to publish the result on Android Market, this id will be used to track updates for the app, so it is important make sure this id is unique... Although we use the name com.my.first.project here, for a real application it is better to choose something like com.yourcompanyname.yourapplication.

    SDK versions

    The Min SDK Version (the name speaks for itself) is the most early version Android on which the application will run. With each new release of Android, the SDK adds and changes various methods. When you select an SDK version, Android (and Android Market) knows that your app will only work on devices with the specified version and above.

    Running your application

    Now let's try to run our application in Eclipse. Since this is the first launch, Eclipse will ask which type of project you are working with:

    • Please select Run-> Run or press Ctrl + F11.
    • Please select Android Application and press OK.

    Eclipse will try to run the application on an Android device. At the moment, however, you have no devices under Android, so the project will fail and you will be prompted to create a new device Android Virtual Device(AVD).

    Virtual Devices (Android Virtual Devices)

    Android Virtual Device (AVD) emulates the Android environment, be it a mobile phone or a tablet PC. You can create as many AVDs as you want, with different versions of the Android platform. For each AVD, you can configure different device parameters, specifying the presence of a physical keyboard, GP support, camera resolution, and so on.

    Before running the application, you must create your first AVD with the SDK Platform (Google API, 1.6).

    In this guide, you will learn how to get started developing for Android, namely: mobile applications on Android Eclipse + SDK platform. Today there are many approaches to developing and building mobile applications for Android. Sophisticated hardware devices, tablet PCs and various software platforms(Symbian OS, iOS, WebOS, Windows Phone 7 ...) open up endless space for developers.

    So, the list of applications to start developing mobile applications for Android is huge. Which platform should you choose? What programming language to learn? Which set of applications to choose for project planning? In this guide, you will learn how to get started developing mobile apps for the Android platform, the open source mobile OS from Google.

    Why Android platform?

    Android is an open platform based on Linux kernel... It has been installed on thousands of devices from a wide range of manufacturers. Android provides apps for all kinds of hardware imaginable in modern mobile devices- digital compasses, camcorders, GPS, sensors and more.

    Free Android development tools get you started quickly creating free or near-free apps. When you are ready to show your program to the world, you can publish it through the Android Market. Publishing to Android Market requires a one-time registration fee ($ 25 at the time of writing) and unlike the App Store Apple(which is very strict about censorship) makes your application available for download and purchase after a quick review - as long as the application does not break the rules and the law.

    Here are a few other Android SDK differences that offer you benefits as a developer:

    • The Android SDK is available for Windows, Mac and Linux, so you don't have to pay for new hardware to write applications.
    • SDK built into Java. If you are familiar with the Java programming language, you are already halfway there.
    • Taking into account the distribution of the application through the Android Market, it will be immediately available to hundreds of thousands of users. You are not limited to just the official Market as there are alternatives. For example, you can publish the app on your blogs. Amazon is rumored to be preparing its own Android app store.
    • As well as the technical documentation for the SDK, new resources are being created for Android developers. The platform is gaining more and more popularity among users and developers.

    Stop talking - let's start developing Android apps!

    Installing Eclipse and Android SDK

    Orientation for the Android platform during development

    Before you start writing Android apps, you need to download the Android SDK. Each platform has its own version of the Android SDK that is installed on users' devices. There are two platforms for Android 1.5 and higher: Android Open Source Project and Google.

    The Android Open Source Project is an open source platform, but does not include Google extensions such as Google Maps. If you do not want to use the Google API, the Google Maps functionality will not be available for your application. Unless you have a specific reason to do this, I would recommend that you target one of Google's platforms, as this will allow you to use Google's own extensions.

    • Select Window-> Android SDK and AVD Manager.
    • Click Available Packages in the left column and check the repository to show a list of available Android platforms.
    • You can select platforms to download from the list, or leave all checked to download all available platforms. When finished, click Install Selected and follow the installation instructions.

    Once everything has been successfully downloaded, you are ready to start developing for Android.

    Creating a new Android project

    The Eclipse New Project Wizard guides you through building your Android application by generating files and code ready to run to the right of the block. This is a quick way to make sure it works and is a good starting point when starting your application development:

    After clicking Finish, Eclipse will create a new Android project, ready to run and develop on Android. Remember you told Eclipse to generate an Activity named BrewClockActivity? This is the code that Android actually uses to launch the application. The generated code will be displayed as a simple ‘Hello World’ message.

    Packages

    The package name is the identifier for your application. When it's time to publish the result to the Android Market, this ID will be used to track updates for the app, so it's important to make sure this ID is unique. Although we are using the name com.example.brewclock here, for a real application it is better to choose something like com.yourcompanyname.yourapplication.

    SDK versions

    Min SDK Version (the name speaks for itself) is the earliest Android version that the application will run on. With each new release of Android, the SDK adds and changes various methods. When you select an SDK version, Android (and Android Market) knows that your app will only work on devices with the specified version of the Android platform and above.

    Running your application

    Now let's try to run our application in Eclipse. Since this is the first launch, Eclipse will ask which type of project you are working with:

    • Select Run-> Run or press Ctrl + F11.
    • Select Android Application and click OK.

    Eclipse will try to run the application on an Android device. At this point, however, you do not have any Android devices, so the project will fail and you will be prompted to create a new Android Virtual Device (AVD).

    Virtual Devices (Android Virtual Devices)

    Android Virtual Device (AVD) emulates the Android environment, be it a mobile phone or a tablet PC. You can create as many AVDs as you want, with different versions of the Android platform. For each AVD, you can configure different device parameters, specifying the presence of a physical keyboard, GP support, camera resolution, and so on.

    Before running the application, you must create your first AVD with the SDK Platform (Google API, 1.6).

    Let's do it now:

    • If you haven't tried running the application yet, press Run (or the keyboard shortcut Ctrl + F11)
    • When the warning pops up, click Yes to create the AVD.
    • Click New in the Android SDK and AVD Manager dialog.
    • Set the following parameters for AVD: Name: Android_1.6 Target: Google APIs (Google Inc.) - API Level 4 SD Card Size: 16 MiB Skin Built In: Default (HVGA)
    • Click Create AVD.
    • Close the Android SDK and AVD Manager dialog.

    Running the code

    Try starting the application again (Ctrl + F11). Eclipse will now build your project and launch a new AVD. Remember, AVD completely emulates the Android environment, and you don't even need to observe the slow enough boot process, as is the case with a real device. For this reason, once the AVD is ready to go, it is best not to close the window until you have finished programming, all day long.

    Android development: user interface design

    One of the first steps to creating any program in general is designing user interface... Here's a small sketch of our application:

    The user will be able to set the boil time in minutes using the + and - buttons. When he clicks Start, the countdown will begin for the specified number of minutes. If the user cancels boiling by pressing the button again, the time will increase when the timer reaches 0.

    Building the interface

    The Android user interface, or wrapper, which is described in the XML documentation, can be found in the res / layouts folder. The template code already generated by Eclipse is declared in res / layouts / main.xml and, as you can see, is already working in the emulator.

    Eclipse has its own layout design toolkit that allows you to create a drag-and-drop interface within the screen. However, it is sometimes easier to write the interface in XML and use a graphical layout to preview the results.

    Let's do it now by modifying main.xml according to the sketch above:

    • Open res / layouts / main.xml in Eclipse by double clicking from Package Explorer.
    • Select the main.xml tab at the bottom of the screen to switch to XML mode.

    Now let's change the content of main.xml to the following:

    # /res/layouts/main.xml