Tuesday, 3 January 2012

FrameLayout


FrameLayout is designed to display a single item at a time. You can have multiple elements within a FrameLayout but each element will be positioned based on the top left of the screen. Elements that overlap will be displayed overlapping. I have created a simple XML layout using FrameLayout that shows how this works.
<FrameLayout 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         xmlns:android="http://schemas.android.com/apk/res/android">
         <ImageView 
                 android:src="@drawable/icon"
                 android:scaleType="fitCenter"
                 android:layout_height="fill_parent"
                 android:layout_width="fill_parent"/>
         <TextView
                 android:text="android-guide-sss.blogspot.com"
                 android:textSize="24sp"
                 android:textColor="#000000"
                 android:layout_height="fill_parent"
                 android:layout_width="fill_parent"
                 android:gravity="center"/>
</FrameLayout>
Here is the result of this XML.


Absolute Layout


AbsoluteLayout
AbsoluteLayout is based on the simple idea of placing each control at an absolute position.  You specify the exact x and y coordinates on the screen for each control.  This is not recommended for most UI development (in fact AbsoluteLayout is currently deprecated) since absolutely positioning every element on the screen makes an inflexible UI that is much more difficult to maintain.  Consider what happens if a control needs to be added to the UI. You would have to change the position of every single element that is shifted by the new control.
Here is a sample Layout XML using AbsoluteLayout.
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
         android:id="@+id/backbutton"
         android:text="Back"
         android:layout_x="10px"
         android:layout_y="5px"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />
    <TextView
         android:layout_x="10px"
         android:layout_y="110px"
         android:text="First Name"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />
    <EditText
         android:layout_x="150px"
         android:layout_y="100px"
         android:width="100px"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />
  
 <TextView
         android:layout_x="10px"
         android:layout_y="160px"
         android:text="Last Name"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />
         <EditText
         android:layout_x="150px"
         android:layout_y="150px"
         android:width="100px"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />
</AbsoluteLayout>
Note how each element has android:layout_x and android:layout_y specified. Android defines the top left of the screen as (0,0) so the layout_x value will move the control to the right, and the layout_y value will move the control down. Here is a screenshot of the layout produced by this XML.


Layouts in ANdroid


Layout:
An Android layout is a class that handles arranging the way its children appear on the screen.  Anything that is a View (or inherits from View) can be a child of a layout. All of the layouts inherit from ViewGroup (which inherits from View) so you can nest layouts.  You could also create your own custom layout by making a class that inherits from ViewGroup.
The standard Layouts are:
AbsoluteLayout
FrameLayout
LinearLayout
RelativeLayout
TableLayout



Modify your Project :


Renaming Parts of an Application

Sometimes a portion of an Android project needs to be renamed. Maybe a file was copied manually into the project, such as from this book. Maybe the application name has changed during development, and it needs to be reflected in the file system tree. Automatic tools help with this and ensure cross-references are automatically updated. For example, in the Eclipse IDE, the different ways to rename portions of an application are



 Rename the Android project, as follows:



1. Right-click the project and Refactor > Move to a new directory in the

    File system.

2. Right-click the project and Refactor ­> Rename the project.



Rename an Android package, as follows:



1. Right-click the package and Refactor > Rename the package.

2. Edit the AndroidManifest.xml to ensure the new package name is reflected.



Rename an Android class (such as the major components Activity, Service, BroadcastReceiver, ContentProvider), as follows:

1. Right-click the .java file and Refactor > Rename the class.

2. Edit the AndroidManifest.xml to ensure the android: name has the new

component name.
Note that renaming other files, such as XML files, usually requires manually changing the corresponding references in the Java code.

Project's Folder Structure



1.     src(Source folder)/: holds the Java source code for the application.

2.     gen(generated folder)/ : contain R.java file. R.java file contains the id’s of all component in hex code.

3.     assets/: holds other static files you wish packaged with the application for deployment.

4.     res(resource)/ holds resources, such as icons, GUI layouts, and the like, that get packaged with the compiled Java in the application.

5.     AndroidManifest.xml: an XML file describing the application being built and what components—activities, services, etc.—are being supplied by that application.

6.     default.properties, a property file used by the Ant builds script.

HelloWorld Program


How to Create Hello world Application in Android
Start the eclipse > click on file > new > Android Project
(Some time you have to select new > others > Android Project)

Give the name of project like Hello(what ever you want you can give the name of project)



Then click finish.
Select your project right click the Run As > Android Application
Wait for some time after that you will get the output in the emulator.


Monday, 2 January 2012

First Step For Android



How to install Android :

Step 1: Get jdk, download from: http://javadl.sun.com/webapps/download/
Then Install Jdk1.6 or higher version.

Step 2: Set Global path:

Windows XP
1.     Select Start, select Control Panel. Double click System, and select the advanced tab.
2.     Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
3.     In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
Windows Vista:
From the desktop, right click the My Computer icon.
1.     Choose Properties from the context menu.
2.     Click the Advanced tab (Advanced system settings link in Vista).
3.     Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
4.     In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
Windows 7:
From the desktop, right click the Computer icon.
1.     Choose Properties from the context menu.
2.     Click the Advanced system settings link.
3.     Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
4.     In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

Steps 3:

Get Eclipse (I use Eclipse 3.7 – Indigo/Helios),


Step 4: Installing Android development tool (ADT) for eclipse IDE

            Start the eclipse > select Help > Install New Software.


Click next and accept the terms and conditions and click Finish.

Note: when installation is about to finish then it ask restart the eclipse at that time select ok, it is mandatory.

Step 5: Install the android Software development Kit (SDK)

Download the android SDK


Step 6:

Open eclipse go to > Windows > Preferences >



Clicks apply and OK

Step 7: Setting up Android Virtual Device (AVD)

            In eclipse go to > Windows > Android SDK and AVD Manager



Fill the Details-

Name-Give the name of Emulator

Target-select API Level 7/8/9/12

Size –no need to give size (optional)

Built-in –WQVGA400 (select according to you)