Posts Tagged ‘new android project’

Linear Layout in Android

November 15th, 2011 by aabhaanjan
This example is for Linear views :
Steps :
Step 1. Create a new android project.
Step 2. Give the project name.
Step 3. Open res/layout/main.xml
There is a root LinearLayout that defines its orientation to be vertical and horizontal.
Step 4. Here is the code :
[xml]
<?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”>
<LinearLayout
android:orientation=”horizontal”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:layout_weight=”1″>
<TextView
android:text=”column one”
android:gravity=”center_horizontal”
android:background=”#aa0000″
android:layout_width=”wrap_content”
android:layout_height=”fill_parent”
android:layout_weight=”1″/>
<TextView
android:text=” column two”
android:gravity=”center_horizontal”
android:background=”#00aa00″
android:layout_width=”wrap_content”
android:layout_height=”fill_parent”
android:layout_weight=”1″/>
</LinearLayout>
<LinearLayout
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:layout_weight=”1″>
<TextView
android:text=”row one”
android:textSize=”15pt”
android:gravity=”center_vertical”
android:background=”#000000″
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_weight=”1″/>
<TextView
android:text=”row two”
android:textSize=”15pt”
android:gravity=”center_vertical”
android:background=”#aaaaaa”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:layout_weight=”1″/>
</LinearLayout>
</LinearLayout>
[/xml]
Step 5.Run you app. it will look like this :

droid_tool

This example is for Linear views :

Steps :

Step 1. Create a new android project.

Step 2. Give the project name.

Step 3. Open res/layout/main.xml

There is a root LinearLayout that defines its orientation to be vertical and horizontal.

Step 4. Here is the code :

[xml]

<?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”>

<LinearLayout

android:orientation=”horizontal”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”

android:layout_weight=”1″>

<TextView

android:text=”column one”

android:gravity=”center_horizontal”

android:background=”#aa0000″

android:layout_width=”wrap_content”

android:layout_height=”fill_parent”

android:layout_weight=”1″/>

<TextView

android:text=” column two”

android:gravity=”center_horizontal”

android:background=”#00aa00″

android:layout_width=”wrap_content”

android:layout_height=”fill_parent”

android:layout_weight=”1″/>

</LinearLayout>

<LinearLayout

android:orientation=”vertical”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”

android:layout_weight=”1″>

<TextView

android:text=”row one”

android:textSize=”15pt”

android:gravity=”center_vertical”

android:background=”#000000″

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

android:layout_weight=”1″/>

<TextView

android:text=”row two”

android:textSize=”15pt”

android:gravity=”center_vertical”

android:background=”#aaaaaa”

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

android:layout_weight=”1″/>

</LinearLayout>

</LinearLayout>

[/xml]

Step 5.Run you app. it will look like this :

LinearView

Tags: , , , , ,

Android Hello world Program

November 15th, 2011 by aabhaanjan

Android Hello world Program :
Lets start with hello world program. Here we will learn how to write
a hello world program in android :
Step 1 :Create New android Project.

1

Step 2 :Give the Project Name and choose SDK version.

2

Step 3 :The manifest file.

3

step 4 : Here is code :

Code of used classes :
Activity Class :
[xml]
package com.helloworldandroid;

import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText(“Hi This is your first Program”);
setContentView(tv);
}
}
[/xml]

R.Java :
[xml]
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/

package com.helloworldandroid;

public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

[/xml]

res/layput/main.xml :
[xml]
<?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”
>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello”
/>
</LinearLayout>
[/xml]
Step 5 : Run your application :- It will look like this
4

Tags: , , , , , ,