Saturday, August 20, 2011

Layout's In Android


Today we are going to see the different layouts in Android.For that we need to understand what is layout.which are given below.
What is Layout?
Layout is the architecture for user Interface(UI) in the activity.It defines layout structure and holds all the elements which are visible to the user.

How to declare Layout?
1. Declare UI element in XML.(Such as TextView, Button)
2. Create UI at run time.(in .java file)

Where to place XML file in your project.

your_project_name > res > layout > your_file_name.xml

Here we are declaring UI element in XML.We are not creating UI at run-time. So Lets start with Absolute Layout.Basically there are five layout's in Android. All layout's are subclass of ViewGroup.Explained below.
1. Absolute Layout
2. Frame Layout
3. Table Layout
4. Linear Layout
5. Relative Layout


1. Absolute Layout
Let’s start with Absolute layout. In Absolute Layout you have to mention X and Y coordinate of the screen for the respective component. This layout is not used for the development of UI. Because it is quite difficult to set absolute position of each element in the UI. Consider if we need to add or remove any component at that time we need to set the position of each and every component. I have designed Login page using Absolute Layout.
Here is the xml code for using Absolute Layout.














Here is the output of Absolute Layout.
  
  
2. Frame Layout
In Frame Layout all the contents are placed in one frame. You can add multiple elements in it but all the component will overlap with each other. And top element will be visible to you. I have designed simple XML file using frame layout. In the sample xml file button is overlapping TextView hence the rest of text is visible to you.This is xml code for Frame Layout :-














This is the output for Frame Layout.


3. Table Layout
In Table Layout you have to put the contents in rows or in columns. TableRow is child view of the Table Layout. Where each table row defines one row in the table. Each row may contain one or more column. And columns are hidden in android. You have to stretch it and fill the available screen.
Here is xml code for Table Layout.














This is the output for Table Layout.















4. Linear Layout
In Linear Layout all the elements are placed in line by line either horizontally or vertically. I have designed simple login page using this layout. I have put the screen shot. If we put the orientation of the layout as vertical then we will be able to see the simple login page which is shone below.Where all the elements will be visible one after another. The .xml code for linear layout with vertical orientation is shown below.















This is output with vertical orientation.















But if we change the orientation from vertical to horizontal then we will not be able to see the rest of content. Since elements are placed in one by one fashion.Which will look in the next screen shot given below.















5. Relative Layout
In Relative Layout all the elements are placed in relative to each other. In this layout all the child are placed in relative to the parent view or each other. I have designed simple login page using Relative Layout.The .xml code for relative layout is given below.















This is the output for Relative Layout.















This is what the different layout's in Android.

Thursday, August 11, 2011

Hello World Android

Hello Friends,
           Welcome to the world of Android. When I started Android development I ran through various difficulties.So I wish my other fellow Android developer should not get same trouble.Hence Today I will explain you how to write simple Hello World example in Android.Now Let's Start..............
           First step is to prepare  Android development environment.Following are the requirement for Android development.I am using Eclipse(Helios) along with Window 7 (32-bit).

Basic Requirement for the Hello World
1) JDK  
              JDK is required for the installation of eclipse.To download JDK  Click Here.
2) Eclipse Helios or Higher Version.
             You can download eclipse Helios(32-bit) form here.For different version you can get it from here. Now extract the folder at some safe location and run the .exe file.Before starting eclipse it will ask you where you want to place your workspace.Locate it to some safe location.
3) Android-sdk
             You can download Android-sdk for windows from here.For other operating system you can get it from here.Place it some safe location. And run SDK Manager in the android-sdk folder.
4) ADT-Plugin
             For installing ADT-Plugin you need to start eclipse and follow the steps.
   a) Click on Help > Install New Software.
   b) Click Add, in the top-right corner.
   c) In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for        the Location:
                 https://dl-ssl.google.com/android/eclipse
   d) Click OK
   e) Now select the check box and click next.
   f) Follow the instruction and complete the installation.Now you need to restart eclipse.

Now you are ready with Android development Environment.
5) Android Emulator.
          After setting Android Environment you need to create AVD(Android Virtual Device).AVD is used to run your Android application.It works same as like that of your android phone except certain feature.For that start eclipse and go to Windows> Android SDK and AVD Manager. You will get following screen.


             From here go to New tab on right corner of the image.From where you can create AVD. Assign name whatever you want and assign the target.I am using Android 2.3 as a target.This is simple task you have to do for creating AVD.
             From here onwards main task is started.Now move to left corner of your eclipse click on New > Project > Android Project. Now you need to set following parameter.

1) Name of your project > Hello World Tutorial
2) Build Target (Android 2.3)
3) Application Name :- Hello World Tutorial
4) Package Name :- com.android.pmts
5) Create Activity :- HelloAndroid
6) Min sdk version : 9

After completing all these fields you will get following screen.




And your project structure will look like this :-




Now open your HelloAndroid.java class and add the following lines.
                   
// These lines are used to display the text.
 Toast.makeText(getApplicationContext(), "Hi, This is Hello World Tutorial",2000).show();

So your HelloAndroid.java class will look like this :-


Now your First Hello World Tutorial is ready.Now you need to run this application.For that go to  Run > run or use Ctrl+F11 or right click on your project i.e. Hello World Tutorial and select Run As > Android Application. It will start your AVD which we have crated previously and you will get the output something like shown below.




This is what the simple thing you have to do for creating Hello World program.
Hope you find it useful to start Android development.Because we believe in "Learning And Sharing". Please leave a comment so that we can improve this blog.

If you are having any queries you can send me mail at coe@parallelminds.biz


Monday, August 8, 2011

Hello Android

Hi Friends,
This is our new blog after huge response for our sharpointing and dotnetminders for learning and sharing all about android developement.We are planning to post following articles in android
1.How to set up Step By Step preparing android developement Environment
2.Hello world android programme
3.Data access in android
4......and many more
So stay tuned