Practical No 6
Practical No 6
Practical No. 6: Develop a program to implement frame layout, table layout and
relative layout
I. Practical Significance
To develop and place the android components accurately on the display screen,
android provides various layout managers. Layout managers can be used on the
simple android program too. Various layout managers can be selected as per the
program requirements.
2. Relative Layout:
A Relative Layout is a very powerful utility for designing a user interface because it can
eliminate nested view groups and keep your layout hierarchy flat, which improves
performance. If you find yourself using several nested Linear Layout groups, you may be
able to replace them with a single Relative Layout.
3. Table Layout:
A Table Layout consists of a number of Table Row objects, each defining a row (actually,
you can have other children, which will be explained below). Table Layout containers do
not display border lines for their rows, columns, or cells. Each row has zero or more cells;
each cell can hold one View object. The table has as many columns as the row with the
most cells. A table can leave cells empty. Cells can span columns, as they can in HTML. The
width of a column is defined by the row with the widest cell in that column.
1.
android:id, android:padding, android:layout_height, android:layout_width etc.
2.
GridLayout is a layout that places its children in a rectangular grid.
The grid is composed of a set of infinitely thin lines that separate the viewing area into cells.
Throughout the API, grid lines are referenced by grid indices. A grid with N columns has N + 1 grid
indices that run from 0 through N inclusive. Regardless of how GridLayout is configured, grid index 0 is
fixed to the leading edge of the container and grid index N is fixed to its trailing edge (after padding is
taken into account).
X. Exercise
Note: Faculty must ensure that every group of students use different input value.
(Use blank space for answers or attach more pages if needed)
1. Write a program to display 10 students basic information in a table form using Table
layout.
2. Write a program to display all the data types in object-oriented programming using
Frame layout.
1.
//MainActivity.java
package com.jamiapolytechnic.experiment61;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
//=====================================================================
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Roll No."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" />
<TextView
android:text="Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" />
<TextView
android:text="Branch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Khan Kamaal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2" />
<TextView
android:text="TYCO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Khan Jamaal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="TYCO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Khan Nihaal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="TYCO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Khan Hilaal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="TYCO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Khan Bilaal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="TYCO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Shaikh Kaleem"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="TYCO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Shaikh Saleem"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="TYCO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="8"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Shaikh Aleem"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="TYCO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="9"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Shaikh Naeem"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="TYCO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="10"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Shaikh Shaheem"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="TYCO"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
2.
//MainActivity.java
package com.jamiapolytechnic.experiment62;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
//=====================================================================
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:src="@drawable/img1"
android:scaleType="fitCenter"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
<TextView
android:text="@string/data_types"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textColor="#ffffffff"
android:gravity="center"/>
</FrameLayout>
//=====================================================================
//strings.xml
<resources>
<string name="app_name">Experiment62</string>
<string name="data_types">
<b>OOP Data Types: \n</b>
byte, short, int, long, \n
float, double,\n
char, \n boolean, \n
class, interface
</string>
</resources>
1
2
3
4