Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Oaish Qazi 1|Page

Practical No 6:

Q. Write a Program to display 5 students’ basic information in a table using Table Layout.
CODE:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
tools:context=".MainActivity">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Roll no"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Marks"
android:layout_gravity="center"
/>
</TableRow>

<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="210455"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Oaish"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="50"
android:layout_gravity="center"
/>
Oaish Qazi 2|Page

</TableRow>

<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="210454"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Azlan"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="70"
android:layout_gravity="center"
/>
</TableRow>
</TableLayout>

OUTPUT:

Q. Create the below form using Table Layout.

CODE:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
tools:context=".MainActivity">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Column 1"
Oaish Qazi 3|Page

android:gravity="center"
/>
</TableRow>

<TableRow>
<LinearLayout
android:weightSum="2"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Column 2"
android:gravity="center"
android:layout_weight="1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Column 3"
android:gravity="center"
android:layout_weight="1"
/>
</LinearLayout>
</TableRow>

<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Column 4"
android:gravity="center"
/>
</TableRow>
</TableLayout>

OUTPUT:

Q. Create the below form using Frame Layout.


Oaish Qazi 4|Page

CODE:
<?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="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Computer Department"
android:textSize="25dp"
android:gravity="center"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="300dp"
android:layout_gravity="center"
android:src="@drawable/x" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Grade"
android:textSize="25dp"
android:background="#CCC"
android:layout_gravity="bottom|end"
android:layout_margin="20dp"
/>
</FrameLayout>

OUTPUT:
Oaish Qazi 5|Page

Q. Create the below form using Relative Layout.

CODE:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text"
android:text="Sign In"
android:textSize="25dp"
android:gravity="center"
/>
<LinearLayout
Oaish Qazi 6|Page

android:id="@+id/linearLayoutA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/text"
android:layout_marginTop="50dp"
android:padding="5px"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username: "
android:textSize="25dp"
android:gravity="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"
/>
</LinearLayout>

<LinearLayout
android:id="@+id/linearLayoutB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/linearLayoutA"
android:layout_marginTop="30dp"
android:padding="5px"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password: "
android:textSize="25dp"
android:gravity="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Password"
/>
</LinearLayout>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/linearLayoutB"
android:text="Sign In"
android:layout_marginTop="20dp"
android:layout_marginRight="20dp"
android:layout_alignRight="@id/linearLayoutB"
/>
</RelativeLayout>
Oaish Qazi 7|Page

OUTPUT:

Q. Create the below form using Relative Layout.

CODE:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/title"
android:text="My Application"
android:background="#008376"
android:textColor="@color/white"
android:gravity="center_vertical"
android:padding="10dp"
/>
Oaish Qazi 8|Page

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:layout_marginHorizontal="20dp"
android:layout_below="@+id/title"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:layout_marginHorizontal="20dp"
android:layout_toRightOf="@+id/button1"
android:layout_below="@id/title"
/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="20dp"
android:layout_below="@id/button1"
/>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="25dp"
android:layout_marginTop="20dp"
android:layout_below="@id/button3"
>
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Id: "
android:textSize="20dp"
/>
<EditText
android:id="@+id/edit_text"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="10dp"
android:layout_toRightOf="@id/text_view"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:layout_below="@id/edit_text"
android:layout_alignLeft="@id/edit_text"
Oaish Qazi 9|Page

android:layout_marginTop="10dp"
/>
</RelativeLayout>
</RelativeLayout>

OUTPUT:

Q. Create the below form using Relative Layout.

CODE:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Oaish Qazi 10 | P a g e

tools:context=".MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:layout_marginLeft="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@+id/button1"
/>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:layout_centerVertical="true"
/>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 4"
android:layout_centerInParent="true"
/>
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
/>
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
/>
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 7"
Oaish Qazi 11 | P a g e

android:layout_centerHorizontal="true"
android:layout_above="@id/button6"
/>
</RelativeLayout>

OUTPUT:

You might also like