Friday, 11 March 2016

Types of Layout

When a new android project is created main.xml layout file is generated by default. In Netbeans LinearLayout  is default layout.There are six type of layout in android:-

1.     Linear Layout
2.     Relative Layout
3.     Table Layout
4.     Absolute Layout
5.     Frame Layout
6.     List View
7.     Grid View

Linear Layout: Android 'LinearLayout' is a view group that aligns all children in single direction either horizontal or vertical. The default orientation is horizontal.
Some of the basic attribute of Linear Layout.

Attributes
Description
android:id
ID which uniquely identifies layout
android:baselineAlign
This is a Boolean value which must be set true or false. It prevents layout from aligning its children baseline.
android:gravity
This specifies how object should position its content on both X and Y axis.
android:orientation
This specifies direction of all objects in layout. It can be either set to horizontal or vertical. Default orientation is horizontal
android:weightSum
Defines the maximum weight sum.
android:background
Sets background image

Example code for Linear Layout


Relative Layout: Android RelativeLayout enables you to specify how child views are positioned relative to each other. The position of each view can be specified as relative to sibling elements or relative to the parent.

Attributes
Description
android:id
ID which uniquely identifies layout
android:gravity
This is a Boolean value which must be set true or false. It prevents layout from aligning its children baseline.
android: ignoreGravity
This indicates what view should not be affected by gravity.

By default, all child views are drawn at the top-left of the layout, position of each view must be defined using the various layout properties available from RelativeLayout.

Example for Relative Layout

 



Table Layout:  Android TableLayout groups views into rows and columns. You will use the <TableRow> element to build a row in the table. Each row has zero or more cells; each cell can hold one View object.
TableLayout containers do not display border lines for their rows, columns, or cells.

Attributes
Description
android:id
This is the ID which uniquely identifies the layout.
android:collapseColumns
This specifies the zero-based index of the columns to collapse. The column indices must be separated by a comma: 1, 2, 5.
android:collapseColumns
The zero-based index of the columns to shrink. The column indices must be separated by a comma: 1, 2, 5.
android:stretchColumns
The zero-based index of the columns to stretch. The column indices must be separated by a comma: 1, 2, 5.

Code for table layout



Absolute Layout: An Absolute Layout lets you specify exact locations (x/y coordinates) of its children. Absolute layouts are less flexible and harder to maintain than other types of layouts without absolute positioning.

Attributes
Description
android:id
This is the ID which uniquely identifies the layout.

android:layout_x
This specifies the x-coordinate of the view.
android:layout_y
This specifies the y-coordinate of the view






Adding Background Image to your application Netbeans

1. Create a new android application in Netbeans.
2. Copy your image file to /res/drawable directory
(Note: Name of image file should be in small letter)



3 Open main.xml file and add following line to it.

        android:background="@drawable/hd_bg"

Here "hd_bg" is image file name without extension.
Your main.xml file should look like this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="@drawable/hd_bg"
>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hello World, MainActivity"
    />
</LinearLayout>
Save and run application.



Thursday, 10 March 2016

Android Programming Hello World -Using NetBeans

Android Programming Hello World -Using NetBeans

Step 1: Go to File>New Project or
              Press Ctrl+Shift+N

Step 2: Select Android Project 


Step 3: Fill Project name and package name. Project name must not contain space and package name must have three pare example:- com.testrun.helloworld . Now click finish.

Step 4: Project will show error.

Step 5: Build project to remove error


After application is build all errors will be removed.


Step 6: Run application.

Select an emulator from list






Emulator will take time to start up and will run your application.
You can check deployment progress in output android development  tab.