Portrait and Landscape Layouts

While you are developing your mobile application, you always have to think in the user side, and how your application will provide fast and quality results (those could be data, screens, services, etc) for the user. Not only think in HOW, but envision if is going to be that effectively. Now we got the point. One factor that always influences users of the way they see a game or an application is the way of the screen is disposed.

When you are developing your application, Android framework make it easy for you. You just do your application, and when the cellphone go to landscape, is a different the way you have thought. And everything could be changed of place, it would be not aligned as you designed and a headache just starts.

I will show will, a little application and the way it behaves in Portrait and Landscape. And a way to define your Landscape as you wish.

Here, we have a simple application, a Temperature Converter:

Here. The Layout is set up to Vertical. At this point no problem. But when you turn to landscape, it follows what you have done.

You could this using LinerLayout, TableLayout whichever you want is fine.

Here, I just used the LinearLayout.





See. It just followed what you have set up for the application.

However if you wish to be different in portrait, or landscape, what do you do?






Here we have all the packages that are created when you just created the project.

You see the layout/main.xml , right?

So we should add another layout, the landscape layout to have a “dedicated” layout to landscape. How do we do that? simple!!

So, just create a folder called layout-land to define

your layout and create the main.xml inside.

This main.xml, could be totally different, you could

include more features as well.

But if you want just change the layout to other way

you think is better for the user, you do it.




Here, just a new Landscape layout:

If you noticed, the TextView is different, and the way that components are disposed on the screen too.

Here, I just used other type of Layout, the TableLayout.

This means, you can do your own screens in different ways, or use different resources/components to cause a better impression and usability for the user.

Some mobile applications have better view in Portrait, while others have better view in Landscape. It means, depend of the goal of the application. What it is going to show to the user and if what is being shown is the best way to do it. Sometimes, the way the components are disposed is the key, though. Facilitate the view to the user is always welcome. As I said, it could vary from the simplest application to the most complex.


Android !

What’s up!!!

Did you know what is Android?

If you are a beginner you can start here, if you have notions about programming and android you check here out.

I would say Android is not only a Operating System for mobile devices, but with many frameworks and applications involved in it, we could call it a software stack. This Stack is composed by Frameworks, applications (e.g: Browser, Caller, games, etc),  Virtual Machine (The Dalvik),  mobile devices features (Camera, 3G, EDGE, Touch Screen, GSM or CDMA TEchnology, bluetooth, Wifi, GPS, accelerometer, etc) and in addition a development kit for developers. The SDK for developing and debugging . And the great point in all of this, it is free. An OPEN DEVELOPMENT PLATFORM.

Many companies are adhering Android in their phones like Motorola, HTC, Sony Ericsson, Samsung, etc…

IF you want to start in android world you will need 4 basic things. Eclipse IDE, where you are going to develop android apps, your own apps. Sun’s Java Development Kit, The JDK The Android Software Developer’s Kit (SDK) and the Android developer tool (ADT), the plugin for eclipse (this last one you can download and install by eclipse).

First, Download All those 3 software. Then Install the JDK (whether you do not have it installed).

Download Eclipse and the Android SDK.  If you running on Windows both are going to be zip files. Extract them separated, each one in its folder for example:  C:\eclipse and C:\android. It is just up to you.

One step for windows, you have to edit your Enviromnet Variables and add the C:\android\tools to it.  How? simple.

Right click on My Computer and go to properties. There find the System Properties and then Advanced System settings (or in WinXP just the tab Advanced). The in the second box you look for a variable called path. Click on it and edit it. In the end add the address of android tools. If you have followed my example would be C:\android\tools . This is necessary to make it easier to launch Android tools.

Ok. Time to start Eclipse. Just open it.

Go to Help -> Install New Software

Now click in Add, and then add the android address :

In the Locations you can type: https://dl-ssl.google.com/android/eclipse . Click OK.

The Developer tools will appear. check check it and click on NEXT.

You have to accept the terms of the license and then click Finish.

Restart eclipse.

If you do not get a warning about the plugins are not installed (if yes just install all) go to the Window -> Preferences and then Android as the pic bellow shows



Here you have to add the Android path to eclipse recognize the android API.

When you do that you already can start a New Android Project. But when I do a application I should see a cellphone screen and see my application running in it, right? yeah. So, is it already set up? Let’s check if everything is ok!

Go to Window -> Android SDK and AVD Manager ; Here you will see the packges and the Virtual Device (what would be the cellphone). First Check the packges. If they are not installed, check them and just click install. After that Go back to the Virtual Devices to create a new AVD (Android Virtual Device).  Click New. Then type the name of the AVD, I suggest ” my_avd”. You have to choose a target. The target is the API that you are going to use in your AVD. We could see as Android versions.

Select the version that you want and click “Create AVD”.

Ok. After you Configure the Android development environment is time to start.

Go to File -> New -> Project ; Click in Android Project

Look the image bellow:

First, you have to name your project. We could start with a HelloWorld.

Second, choose the Android API in the list Build Target. There, you will see many Android “versions” and choose any you want to start your project. I recommend you choose the same as you have chose when you configured your AVD.


Then you have 4 fields in blank.

The first one is the application Name. It has to have a name. HelloWolrd.

The name, you will see in the Android menu. The name of your application.

The Second one, the package.  Your application have to be in a package. And the name of this one has to have at least two identifiers. E.G:  android.helloworld or firstapp.android. It is just up to you what name it.

The last, that you need to fill out is the Activity.

—–  Brief explanation  —–

The Android Application is composed by four components. There components are defined by Android architecture.

Activities, Services, Broadcast and Intent Receivers and Content Providers. This post I will talk about the Activities. In the future I will talk about the others. But if you want to read about them, just check this link.

When you create an Android application, your application always have to has an activity. Even a “HelloWorld!”  has one. Activities are that chunk of code running in time. For example, Screens; Each activity shows one screen to the user. If one Activity is not being used, or not actively running the operating system can kills it, so it can conserve more memory.


So, the name of the activity is HelloWorldActivity .

Then click on Finish.

Ok. Now you just started an Android Project. You have your first application ready to run.

Before you run it. Let’s take a look at what we have.

In the src (the source) folder, we have the package that you name it as you wanted.

I just named blog.helloworld . And bellow this directory we the gen folder. It is where you will find the R.java .That is all resources from res directory in Java.

Then we can see the Android library. If you click on it, you will all jars that composes the android library that you have chose before during the project creation.

As a resource, you could have any images, bitmaps, or whatever you need for your application.

The layout tells android how dispose items, things on the screen when applications runs. You can check it out, and you will see a XML file.

Values are outside the source. You can use them anytime. What is this? Values are constants, strings, etc..

At last, we have the manifest. The manifest a XML file too. This file defines all components in your application and tell Android about all components that exists in your application.  So, it learn and know about all components in your application before build it.

Now, go to the strings.xml file. And just edit the line that you see HelloWorld. This is going to be the output. You can see in the next line. The name of your application.

Right click on the project and then click on Run As -> Android Application

Pan, Pan Pan Paaaannn!!!

Now the your application is going to run in the emulator, the AVD that you have created.

The Java is going to start too.

You will see that the emulator is like a virtual machine.  So you will see a cellphone on your screen. Just go the menu and find your application and click on it. It will start to running and congrats, you made your first Android App!!