MC File DHRUV GOEL 44114802717

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

MOBILE COMPUTING

ETIT-452

Faculty Name: Mr. Anupam Kumar Student Name: Dhruv Goel


Roll No.: 44114802717
Semester: 8th
Group: C8

Maharaja Agrasen Institute of Technology,


PSP Area, Sector – 22, Rohini, New Delhi – 110085

1
MAHARAJA AGRASEN INSTITUTE OF TECHNOLOGY
VISION
To nurture young minds in a learning environment of high academic value and imbibe spiritual
and ethical values with technological and management competence.
MISSION
The Institute shall endeavor to incorporate the following basic missions in the teaching
methodology:
Engineering Hardware – Software Symbiosis
Practical exercises in all Engineering and Management disciplines shall be carried out by
Hardware equipment as well as the related software enabling a deeper understanding of basic
concepts and encouraging inquisitive nature.
Life-Long Learning
The Institute strives to match technological advancements and encourage students to keep
updating their knowledge for enhancing their skills and inculcating their habit of continuous
learning.
Liberalization and Globalization
The Institute endeavor’s to enhance the technical and management skills of students so that
they are intellectually capable and competent professionals with Industrial Aptitude to face the
challenges of globalization.
Diversification
The Engineering, Technology, and Management disciplines have diverse fields of studies with
different attributes. The aim is to create a synergy of the above attributes by encouraging
analytical thinking.
Digitization of Learning Processes
The Institute provides seamless opportunities for innovative learning in all Engineering and
Management disciplines through digitization of learning processes using analysis, synthesis,
simulation, graphics, tutorials, and related tools to create a platform for a multi-disciplinary
approach.
Entrepreneurship
The Institute strives to develop potential Engineers and Managers by enhancing their skills and
research capabilities so that they become successful entrepreneurs and responsible citizens.

2
MAHARAJA AGRASEN INSTITUTE OF TECHNOLOGY

COMPUTER SCIENCE & ENGINEERING DEPARTMENT


VISION
To Produce “Critical thinkers of Innovative Technology”
MISSION
To provide an excellent learning environment across the computer science discipline to
inculcate professional behavior, strong ethical values, innovative research capabilities and
leadership abilities that enable them to become successful entrepreneurs in this globalized
world.

1. To nurture an excellent learning environment that helps students to enhance their


problem-solving skills and to prepare students to be lifelong learners by offering a solid
theoretical foundation with applied computing experiences and educating them about
their professional, and ethical responsibilities.
2. To establish Industry-Institute Interaction, making students ready for the industrial
environment and being successful in their professional lives.
3. To promote research activities in the emerging areas of technology convergence.
4. To build engineers who can look into technical aspects of an engineering solution
thereby setting the ground for producing successful entrepreneurs.

3
Mobile Computing Lab
(ETIT-452)
Lab Assessment Sheet

Student Enrollment No: 44114802717 Student Name: Dhruv Goel

S.No Experiment Marks Signature


Total
with date
Marks

R1 R2 R3 R4 R5

Write a WML program to print a


1 formatted Text on the mobile Screen
using various tags.
Write a WML program to connect
2 multiple cards from the same desk

Write WML program to display table


3 with three columns Image name, Image
and third column contain a hyperlink to
open another card.
Write a WML program to create a form
4 with multiple options.

Write a WML program to use the time


5 control and to trigger on pick event

Write a WML script to find a maximum


6 out of two numbers with help of the
inbuilt function Lang.Max() and to find
absolute value with help of inbuilt
function Lang.abs()
Write a Program in NS3 to Simulate
7 OLSR

1 | Page
Write a Program in NS3 to Simulate
8 AODV

Make an application of your choice using


9 WML or Android.

Write an Android Program design an


10 application using Hybrid Approach.

Overall Comments:

Faculty Name: Mr. Anupam Kumar


Signature:

2 | Page
EXPERIMENT NO. 1
AIM: Write a WML program to print a formatted Text on the mobile Screen using various tags.

Theory:
Attribute Value Description
align left Aligns the paragraph. Default is "left"
right
center
mode wrap Sets whether a paragraph should wrap lines or not.
nowrap
xml:lang language_code Sets the language used in the element
class cdata Sets a class name for the element. The class name is case-
sensitive. An element can be connected to multiple classes.
Multiple class names within the class attribute
are separated by white space
id id Sets a unique name for the element

WML Elements Purpose


<b> Defines bold text
<big> Defines big text
<em> Defines emphasized text
<i> Defines italic text
<small> Defines small text
<strong> Defines strong text
<u> Defines underlined text
<!--> Defines a WML comment
<wml> Defines a WML deck (WML root)
<head> Defines head information
<meta> Defines meta information
<card> Defines a card in a deck
<access> Defines information about the access control of a deck
<template> Defines a code template for all the cards in a deck

3 | Page
Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
"http://www.wapforum.org/DTD/wml13.dtd">
<wml>
<card id="ABC" title="Practical 1">
<p>
Hello World
</p>
<onevent type="ontimer">
<go href="#ABC1"/>
</onevent>
<timer value="50"/>
</card>
<card id="ABC1" title="Practical 1">
<p>
<b>Kishan Sharma</b><br>
<big>Kishan Sharma</big><br>
<em>Kishan Sharma</em><br>
<i>Kishan Sharma</i><br>
<small>Kishan Sharma</small><br>
<strong>Kishan Sharma</strong><br>
<u>Kishan Sharma</u>
</p>
</card>
</wml>

4 | Page
Output:

5 | Page
EXPERIMENT NO. 2

AIM: Write a WML program to connect multiple cards from the same desk.

Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
"http://www.wapforum.org/DTD/wml13.dtd">

<wml>
<card id="CardNo.1" title="Program2Card1">
<p>You Are Visiting Card 1</p>
<do type="accept" name="CardNo.2" label="Continue">
<go href="#CardNo.2"/>
</do>
</card>

<card id="CardNo.2" title="Program2Card2">


<p>You Are Visiting Card 2</p>
<do type="accept" name="CardNo.3" label="Continue">
<go href="#CardNo.3"/>
</do>
</card>
<card id="CardNo.3" title="Program2Card3">
<p>You Are Visiting Card 3</p>
<do type="accept" name="CardNo.1" label="Go Back">
<go href="#CardNo.1"/>
</do>
</card>
</wml>

Output:

6 | Page
7 | Page
EXPERIMENT NO. 3

AIM: Write WML program to display table with three columns Image name, Image and third column
contain a hyperlink to open another card.

Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
"http://www.wapforum.org/DTD/wml13.dtd">

<wml>
<card id="CardNo.1" title="Program3Card1">
<p>
<table columns="3" align="LCR">
<tr>
<td>Image Name</td>
<td>Image</td>
<td>Link</td>
</tr>

<tr>
<td>Thumb Image</td>
<td><img src="thumb.wbmp" alt="Thumb Image"/></td>
<td><anchor><a href="#CardNo.2">CardNo2</a></anchor></td>
</tr>

<tr>
<td>Heart Image</td>
<td><img src="heart.wbmp" alt="Heart Image"/></td>
<td><anchor><a href="#CardNo.3">CardNo3</a></anchor></td>
</tr>
</table>
</p>
</card>
<card id="CardNo.2" title="Program3Card2">
<p>You Are Visiting Card 2</p>
<do type="accept" name="CardNo.3" label="Continue">
<go href="#CardNo.3"/>
</do>
</card>
<card id="CardNo.3" title="Program3Card3">
<p>You Are Visiting Card 3</p>
<do type="accept" name="CardNo.1" label="Go Back">
<go href="#CardNo.1"/>
</do>
</card>
</wml>
8 | Page
Output:

9 | Page
EXPERIMENT NO. 4
AIM: Write a WML program to create a form with multiple options.

Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN"
"http://www.wapforum.org/DTD/wml12.dtd">

<wml>

<card title="Practical4">
<p> Select a Tutorial :
<select>
<option value="htm">HTML Tutorial</option>
<option value="xml">XML Tutorial</option>
<option value="wap">WAP Tutorial</option>
</select>
</p>
</card>

</wml>

Output:

10 | Page
EXPERIMENT NO. 5
AIM: Write a WML program to use the time control and to trigger On pick event.

Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
"http://www.wapforum.org/DTD/wml13.dtd">

<wml>
<card id="ABC" title="Practical 5">
<p>
Hello World
</p>
<onevent type="ontimer">
<go href="#ABC1"/>
</onevent>
<timer value="100"/>
</card>
<card id="ABC1" title="Practical 5">
<p>Select a Tutorial :
<select title="tutorials" name="selection_list">
<option onpick="#xhtml">XHTML Tutorial</option>
<option onpick="#wap">WAP Tutorial</option>
</select>
</p>
</card>
<card id="xhtml" title="Practical 5">
<p>
XHTML stands for EXtensible HyperText Markup Language.
</p>
</card>
<card id="wap" title="Practical 5">
<p>
Wireless Application Protocol (WAP) is a technical standard for accessing
information over a mobile wireless network.
</p>
</card>
</wml>

Output:

11 | Page
12 | Page
EXPERIMENT NO. 6
AIM: Write a WML script to find a maximum out of two numbers with help of inbuilt function
Lang.Max() and to find absolute value with help of inbuilt function Lang.abs().

Code:
lang.max():
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
"http://www.wapforum.org/DTD/wml13.dtd">

<wml>
<card id="card1" title="WMLScript Tutorial">
<p>
<a href="findmax.wmls#findmax()">Find Maximum Out Of Two.</a><br/>
<br>
First Number: $(number1)<br>
Second Number: $(number2)<br>
Maximum One: $(maxnumber)
</p>
</card>
</wml>

lang.abs():
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
"http://www.wapforum.org/DTD/wml13.dtd">

<wml>
<card id="card1" title="WMLScript Tutorial">
<p>
<fieldset title="Enter The Number: ">
n : <input name="N" size="12" format="*N"/>
</fieldset><br/>
<do type="accept" name="CardNo.2" label="Enter">
<go href="findmax.wmls#findabs(-8)"/>
</do>
<br>
</p>
<p>
First Number: $(number)<br>
ABS Number: $(absnumber)
</p>
</card>
</wml>

Custom function[findmax()]:
13 | Page
extern function findmax()
{
var result1 = Dialogs.prompt("Enter 1st number", "");
var result2 = Dialogs.prompt("Enter 2cd number", "");
var maxnum = Lang.max(result1, result2);
WMLBrowser.setVar("number1", result1);
WMLBrowser.setVar("number2", result2);
WMLBrowser.setVar("maxnumber", maxnum);
WMLBrowser.go("p6.wml#card2");
}
extern function findabs(n)
{
var absnum = Lang.abs(n);
WMLBrowser.setVar("number", n);
WMLBrowser.setVar("absnumber", absnum);
WMLBrowser.go("p6.2.wml#card3");
};

Output:

14 | Page
15 | Page
EXPERIMENT NO. 7
AIM: Write a Program in NS3 to Simulate OLSR.

Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/olsr-helper.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-list-routing-helper.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("SimplePointToPointOlsrExample");

int main (int argc, char *argv[])


{
// Users may find it convenient to turn on explicit debugging
// for selected modules; the below lines suggest how to do this
#if 0
LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
#endif

// Set up some default values for the simulation. Use the

Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));


Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));

//DefaultValue::Bind ("DropTailQueue::m_maxPackets", 30);

// Allow the user to override any of the defaults and the above
// DefaultValue::Bind ()s at run-time, via command-line arguments
CommandLinecmd;
cmd.Parse (argc, argv);

// Here, we will explicitly create four nodes. In more sophisticated


// topologies, we could configure a node factory.
NS_LOG_INFO ("Create nodes.");
NodeContainer c;
c.Create (5);
NodeContainer n02 = NodeContainer (c.Get (0), c.Get (2));
16 | Page
NodeContainer n12 = NodeContainer (c.Get (1), c.Get (2));
NodeContainer n32 = NodeContainer (c.Get (3), c.Get (2));
NodeContainer n34 = NodeContainer (c.Get (3), c.Get (4));

// Enable OLSR

NS_LOG_INFO ("Enabling OLSR Routing.");


OlsrHelperolsr;

Ipv4StaticRoutingHelper staticRouting;

Ipv4ListRoutingHelperlist; list.Add (staticRouting, 0);


list.Add (olsr, 10);

InternetStackHelper internet;
internet.SetRoutingHelper (list); // has effect on the next Install ()
internet.Install (c);

// We create the channels first without any IP addressing information


NS_LOG_INFO ("Create channels.");
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer nd02 = p2p.Install (n02);
NetDeviceContainer nd12 = p2p.Install (n12);
p2p.SetDeviceAttribute ("DataRate", StringValue ("1500kbps"));
p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
NetDeviceContainer nd32 = p2p.Install (n32);
NetDeviceContainer nd34 = p2p.Install (n34);

// Later, we add IP addresses.


NS_LOG_INFO ("Assign IP Addresses.");
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i02 = ipv4.Assign (nd02);

ipv4.SetBase ("10.1.2.0", "255.255.255.0");


Ipv4InterfaceContainer i12 = ipv4.Assign (nd12);

ipv4.SetBase ("10.1.3.0", "255.255.255.0");


Ipv4InterfaceContainer i32 = ipv4.Assign (nd32);

ipv4.SetBase ("10.1.4.0", "255.255.255.0");


Ipv4InterfaceContainer i34 = ipv4.Assign (nd34);

// Create the OnOff application to send UDP datagrams of size


// 210 bytes at a rate of 448 Kb/s from n0 to n4
NS_LOG_INFO ("Create Applications.");
17 | Page
uint16_t port = 9; // Discard port (RFC 863)

OnOffHelper onoff ("ns3::UdpSocketFactory", InetSocketAddress (i34.GetAddress (1), port));


onoff.SetConstantRate (DataRate ("448kb/s"));

ApplicationContainer apps = onoff.Install (c.Get (0));

apps.Start (Seconds (1.0));


apps.Stop (Seconds (10.0));

// Create a packet sink to receive these packets


PacketSinkHelpersink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (),
port));

apps = sink.Install (c.Get (3));


apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));

// Create a similar flow from n3 to n1, starting at time 1.1 seconds


onoff.SetAttribute ("Remote", AddressValue (InetSocketAddress (i12.GetAddress (0), port)));
apps = onoff.Install (c.Get (3));
apps.Start (Seconds (1.1));
apps.Stop (Seconds (10.0));

// Create a packet sink to receive these packets apps = sink.Install (c.Get (1));
apps.Start (Seconds (1.1));
apps.Stop (Seconds (10.0));

AsciiTraceHelper ascii;
p2p.EnableAsciiAll (ascii.CreateFileStream ("simple-point-to-point-olsr.tr"));
p2p.EnablePcapAll ("simple-point-to-point-olsr");

Simulator::Stop (Seconds (30));

NS_LOG_INFO ("Run Simulation.");


Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");

return 0;
}

Output:

18 | Page
19 | Page
EXPERIMENT NO. 8
AIM: Write a Program in NS3 to Simulate AODV.

Code:
#include "ns3/aodv-module.h"
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/mobility-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
#include "ns3/v4ping-helper.h"
#include <iostream>
#include <cmath>
using namespace ns3;

class AodvExample{
public:
AodvExample ();
bool Configure (int argc, char **argv);
void Run ();
void Report (std::ostream & os);

private:

// parameters uint32_t size;


doublestep;
doubletotalTime;
boolpcap;
boolprintRoutes;

// network NodeContainernodes;
NetDeviceContainerdevices;
Ipv4InterfaceContainerinterfaces;

private:
void CreateNodes ();
void CreateDevices ();
void InstallInternetStack ();
void InstallApplications ();
};

int main (int argc, char **argv)


{
AodvExampletest;
if (!test.Configure (argc, argv))
NS_FATAL_ERROR ("Configuration failed. Aborted.");
20 | Page
test.Run ();
test.Report (std::cout);
return 0;
}

//-----------------------------------------------------------------------------
AodvExample::AodvExample () : size (10), step (100), totalTime (10), pcap (true), printRoutes (true){}

bool AodvExample::Configure (int argc, char **argv)


{
// Enable AODV logs by default. Comment this if too noisy
// LogComponentEnable("AodvRoutingProtocol", LOG_LEVEL_ALL);

SeedManager::SetSeed (12345);
CommandLinecmd;

cmd.AddValue ("pcap", "Write PCAP traces.", pcap);


cmd.AddValue ("printRoutes", "Print routing table dumps.", printRoutes);
cmd.AddValue ("size", "Number of nodes.", size);
cmd.AddValue ("time", "Simulation time, s.", totalTime);
cmd.AddValue ("step", "Grid step, m", step);

cmd.Parse (argc, argv);


return true;
}

void AodvExample::Run ()
{
// Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", UintegerValue (1));
// enable rts cts all the time.
CreateNodes ();
CreateDevices ();
InstallInternetStack ();
InstallApplications ();

std::cout <<"Starting simulation for "<<totalTime<<" s ...\n";

Simulator::Stop (Seconds (totalTime));


Simulator::Run ();
Simulator::Destroy ();
}

void AodvExample::Report (std::ostream &){}

void AodvExample::CreateNodes ()
{
std::cout <<"Creating "<< (unsigned)size<<" nodes "<<step<<" m apart.\n";
21 | Page
nodes.Create (size);
// Name nodes
for (uint32_t i = 0; i <size; ++i)
{
std::ostringstream os;
os <<"node-"<< i;
Names::Add (os.str (), nodes.Get (i));

}
// Create static grid
MobilityHelpermobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator", "MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0), "DeltaX", DoubleValue (step), "DeltaY", DoubleValue (0),
"GridWidth", UintegerValue (size),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (nodes);
}

void AodvExample::CreateDevices ()
{
WifiMacHelper wifiMac;
wifiMac.SetType ("ns3::AdhocWifiMac");
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
WifiHelperwifi;
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue
("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0));
devices = wifi.Install (wifiPhy, wifiMac, nodes);

if (pcap)
{
wifiPhy.EnablePcapAll (std::string ("aodv"));
}
}

void AodvExample::InstallInternetStack ()
{
AodvHelper aodv;
// you can configure AODV attributes here using aodv.Set(name, value)
InternetStackHelperstack;
stack.SetRoutingHelper (aodv); // has effect on the next Install ()
stack.Install (nodes);
Ipv4AddressHelperaddress;
address.SetBase ("10.0.0.0", "255.0.0.0");
interfaces = address.Assign (devices);
22 | Page
if (printRoutes)
{
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("aodv.routes",
std::ios::out);
aodv.PrintRoutingTableAllAt (Seconds (8), routingStream);
}
}

void AodvExample::InstallApplications ()
{
V4PingHelper ping (interfaces.GetAddress (size - 1));
ping.SetAttribute ("Verbose", BooleanValue (true));

ApplicationContainer p = ping.Install (nodes.Get (0));


p.Start (Seconds (0));
p.Stop (Seconds (totalTime) - Seconds (0.001));
// move node away
Ptr<Node> node = nodes.Get (size/2);
Ptr<MobilityModel> mob = node->GetObject<MobilityModel> ();
Simulator::Schedule (Seconds (totalTime/3), &MobilityModel::SetPosition, mob, Vector (1e5, 1e5,
1e5));
}

Output:

23 | Page
EXPERIMENT NO. 9
AIM: Make an application of your choice using WML.

Code:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"
"http://www.wapforum.org/DTD/wml13.dtd">

<wml>
<card id="CardNo.1" title="Calculator">
<p>
<fieldset title="Enter First Number: ">
Enter First Value: <input format="*N" name="a" title="First Amount:"/>
</fieldset><br/>
<fieldset title="Enter Second Number: ">
Enter Second Value: <input format="*N" name="b" title="Second Value:"/>
</fieldset><br/>
<fieldset>
Operator :
<select name="op" title="Operation:">
<option value="+">Addition</option>
<option value="-">Subtraction</option>
<option value="*">Multiplication</option>
<option value="/">Division</option>
</select><br/><br/>
<do type="accept" name="Calculator" label="Ans(=)">
<go href="calc.wmls#operation($(a),$(b))"/>
</do>
</fieldset>

</p>
</card>
<card id="result" title="Result">
<p>
Here is the result:<br/>
$(a) '$(op)' $(b) = $(result)
</p>
<do type="accept" label="Back">
<prev/>
</do>
</card>
</wml>

Calc.wmls:
extern function operation(a, b)
24 | Page
{
var ans = 0;
var op = WMLBrowser.getVar("op");

if (op == "+"){
ans = a + b;
}
else if (op == "-"){
ans = a - b;
}
else if (op == "*"){
ans = a * b;
}
else if (op == "/"){
ans = a / b;
}
WMLBrowser.setVar("result",ans);
WMLBrowser.go("#result");
}

Output:

25 | Page
EXPERIMENT NO. 10
AIM: Write an Android Program to create a list view.

Code:

package com.example.myapplication;

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

import static com.example.myapplication.R.menu.main;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(main, menu);
return true;
}

<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
>

<!-- This is a comment -->

<!-- Create your comments like this -->

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentTop="true"
android:layout_marginTop="18dp"
26 | Page
android:text="@string/hello_sanfoundry_android" />

<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="53dp"
android:text="This is a Large Text View"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="16dp"
android:text="This is Medium Text View"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:layout_marginTop="14dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView4"
android:layout_below="@+id/textView4"
android:layout_marginTop="16dp"
android:text="Button" />

<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_alignParentRight="true"
android:text="ToggleButton" />

<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
27 | Page
android:layout_alignTop="@+id/button1"
android:layout_centerHorizontal="true"
android:text="Small Button" />

<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/toggleButton1"
android:layout_below="@+id/toggleButton1"
android:layout_marginTop="93dp"
android:text="CheckBox" />

<CheckedTextView
android:id="@+id/checkedTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/checkBox1"
android:layout_alignBottom="@+id/checkBox1"
android:layout_alignLeft="@+id/button1"
android:text="CheckedTextView" />

<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/checkedTextView1"
android:layout_below="@+id/checkBox1"
android:layout_marginTop="34dp"
android:text="RadioButton" />

<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/radioButton1"
android:layout_below="@+id/radioButton1"
android:text="RadioButton" />

</RelativeLayout>

Output:

28 | Page
29 | Page

You might also like