Tuesday, 8 July 2014

Android third lecture



 Third Lecture




Here res is resource in which we have layout. In layout we make the design pattern of our project. And the files in the layout are xml files.
The following are the types of layout:
  • Linear Layout
  • Relative  Layout
  • Grid View
  • List View
  • Custom List
  • Custom Grid
  • Table View
  • Tab View
  • Advance
  • Database
Now here we design our pattern with Linear Layout:
Do the following:
  • First of all Open Eclipse and follow the steps mentioned in *http://androidbydeeksha.blogspot.in/2014/06/android-second-lecture.html
  • Now you are ready to make your program or project.



  • Open res>layout>main.xml
  • Now a screen gets opened.

  • At the bottom of the screen their are two buttons Graphical layout and main.xml as shown below:

  • In Graphical layout we see the pattern we make in our main.xml .
Let's Start with simple project of Login Page by using Linear Layout



Program to make a program as shown in above pictures:

  • Once you have followed the above steps, you are ready to make your program in android.
  • Open the project, suppose you have given the name: SampleAndroidApplication. 

Note: Make sure that you have given the name of your project without space and the alphabet of a particular name should be capital like here it is Sample, Android and Application.






  • Open res>layout>main.xml
  • Click on main.xml
  • Write the coding of layout as follows:
  • Note: we are writing our layout in Linear Layout.


    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <LinearLayout 
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:orientation="vertical">
         <TextView 
             android:layout_height="wrap_content"
             android:layout_width="fill_parent"
             android:text="User name"/>
         <EditText 
             android:layout_height="wrap_content"
             android:layout_width="fill_parent"/>
            
         <TextView 
             android:layout_height="wrap_content"
             android:layout_width="fill_parent"
             android:text="Password"/>
         <EditText 
             android:layout_height="wrap_content"
             android:layout_width="fill_parent"
             />
            <LinearLayout 
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:orientation="horizontal">
            
            <Button 
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:text="Login"
                android:layout_weight="1"
              />
             <Button 
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:text="Cancel"
                android:layout_weight="1"
               />
              </LinearLayout>
                 </LinearLayout>
                 </LinearLayout>
                   
                 


    • Write the above code in main.xml file and see the layout in Graphical Layout.
    • Now open src file.
    • In src file a package will be made and further a class(java class) will be made.
    • Write the following code in that java class:


    package com.cgc.SampleAndroidApplication;

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

    public class SampleAndroidApplicationActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }
    }


    • Now the project has been made.
    • Now open your project.

    Steps to open project.

    Emulator


    • Click on Android virtual device manager icon.
    • A screen gets opened.

    •  Click on New.
    • Give name, target(say 2.1) and give size(say 164).
    • Click on Create AVD.
    • Your AVD will be created. Click on the AVD created and then click on start.

    • A box will get opened and click on Scale display to real size.
    • Give screen size (say 7 or 8).
    • Click on Launch.
    • The emulator gets opened.
    • And it will display your project.

    No comments:

    Post a Comment