Sei sulla pagina 1di 221

MobileApplicationandDevelopment-LabManual

MIDTERM:

Labtaskno.1

LinearLayout:

LinearLayoutisaviewgroupthatalignsallchildreninasingledirection,

verticallyorhorizontally.Youcanspecifythelayoutdirectionwiththe

android:orientationattribute.AnAndroidlayoutisaclassthathandlesarranging

thewayitschildrenappearonthescreen.AnythingthatisaView(orinherits

fromView)canbeachildofalayout.AllofthelayoutsinheritfromViewGroup(which

inheritsfromView)soyoucannestlayouts.Youcouldalsocreateyourowncustom

layoutbymakingaclassthatinheritsfromViewGroup.

1.LinearLayout

2.RelativeLayout

3.ConstraintLayout

Linearlayout#1

DesignView:

pg.1

MobileApplicationandDevelopment-LabManual

MobileApplicationandDevelopment-LabManual Textview: XMLCode: <? xmlversion= "1.0" encoding= "utf-8"

Textview:

XMLCode:

<?xmlversion="1.0"encoding="utf-8"?>

<android.support.constraint.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/colorPrimary"

tools:context="com.thenewlogo.logo.home">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@color/colorPrimary"

android:fontFamily="sans-serif"

android:text="logo"

pg.2

MobileApplicationandDevelopment-LabManual

android:textAppearance="@style/TextAppearance.AppCompat.Display2"

android:textColor="@android:color/background_light" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintHorizontal_bias="0.49"

app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.07"/>

<TextView android:id="@+id/textView"

android:layout_width="281dp"

android:layout_height="31dp"

android:background="@color/colorPrimary" android:fontFamily="sans-serif" android:foregroundTintMode="src_in" android:text="buildyourconnection" android:textAlignment="center" android:textAppearance="@style/TextAppearance.AppCompat.Button" android:textColor="@android:color/background_light"

android:textSize="18sp"

android:textStyle="bold" android:visibility="visible"

tools:layout_editor_absoluteX="55dp"

tools:layout_editor_absoluteY="95dp"/>

<Button

android:id="@+id/button4"

android:layout_width="210dp"

android:layout_height="51dp"

android:background="@color/colorPrimaryDark"

android:text="f|Loginwithfacebook"

android:textAppearance="@style/TextAppearance.AppCompat"

pg.3

MobileApplicationandDevelopment-LabManual

android:textColor="@android:color/background_light"

android:textSize="18sp"

android:textStyle="bold" android:typeface="sans"

tools:layout_editor_absoluteX="87dp"

tools:layout_editor_absoluteY="138dp"/>

<Button

android:id="@+id/button2"

android:layout_width="208dp"

android:layout_height="55dp"

android:background="@color/colorPrimaryDark" android:fontFamily="sans-serif" android:text="ln|loginwithlinkedin" android:textAlignment="center" android:textColor="@android:color/background_light"

android:textSize="14sp"

android:textStyle="bold" android:typeface="normal"

tools:layout_editor_absoluteX="89dp"

tools:layout_editor_absoluteY="208dp"/>

<EditText android:id="@+id/editText"

android:layout_width="213dp"

android:layout_height="42dp"

android:background="@android:color/background_light"

android:ems="10"

android:gravity="clip_horizontal|start|end" android:inputType="textEmailAddress" android:text="EnteryourEmail"

android:textAppearance="@style/TextAppearance.AppCompat.Body2"

android:textColor="@android:color/darker_gray"

android:textSize="18sp"

pg.4

MobileApplicationandDevelopment-LabManual

android:visibility="visible"

tools:layout_editor_absoluteX="85dp"

tools:layout_editor_absoluteY="303dp"/>

<Button

android:id="@+id/button3"

android:layout_width="88dp"

android:layout_height="34dp"

android:background="@android:color/holo_green_dark" android:text="Next" android:textColor="@android:color/background_light"

android:textSize="14sp"

android:textStyle="bold"

tools:layout_editor_absoluteX="209dp"

tools:layout_editor_absoluteY="362dp"/>

<TextView

android:id="@+id/textView3"

android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="---------------or--------------" android:textColor="@android:color/background_light"

android:textSize="24sp"

tools:layout_editor_absoluteX="87dp"

tools:layout_editor_absoluteY="263dp"/>

</android.support.constraint.ConstraintLayout>

Layout#2

TextView:

XMLCode:

pg.5

MobileApplicationandDevelopment-LabManual

<?xmlversion="1.0"encoding="utf-8"?>

<android.support.constraint.ConstraintLayout

xmlns:android="http://schemas.android.com/ apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.thenewlogo.myapplication .MainActivity"> <LinearLayout

android:layout_width="400dp"

android:layout_height="526dp"

android:background="@android:color/background_dark" android:orientation="vertical"

android:weightSum="1"

tools:layout_editor_absoluteX="-8dp"

tools:layout_editor_absoluteY="3dp">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

<ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_weight="0.27"

android:cropToPadding="true"

app:srcCompat="@mipmap/ic_launcher"/>

<TextView

android :cropToPadding= "true" app :srcCompat= "@mipmap/ic_launcher" /> < TextView pg. 6

pg.6

MobileApplicationandDevelopment-LabManual

android:id="@+id/textView7"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginLeft="0dp"

android:layout_marginTop="10dp"

android:layout_weight="1"

android:foregroundGravity="left" android:gravity="center_horizontal|fill_horizontal|center"

android:paddingStart="0dp"

android:paddingTop="0dp"

android:text="HelloWorld" android:textColor="@android:color/background_light" android:textColorLink="@drawable/abc.png"

android:textSize="30sp"

android:textStyle="bold"/>

</LinearLayout>

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"

android:layout_margin="5dp"

android:layout_marginBottom="5dp"

android:layout_marginEnd="5dp"

android:layout_marginLeft="5dp"

android:layout_marginRight="5dp"

android:layout_marginStart="5dp"

android:layout_marginTop="0dp"

android:background="@android:color/background_light" android:orientation="vertical"

android:paddingBottom="5dp"

android:paddingEnd="5dp"

android:paddingLeft="5dp"

android:paddingRight="5dp"

pg.7

MobileApplicationandDevelopment-LabManual

android:weightSum="1">

<TextView

android:id="@+id/textView8"

android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimary" android:text="Anotheractivity" android:textAllCaps="false" android:textColor="@android:color/background_light"

android:textSize="24sp"

android:textStyle="bold"/>

<Button

android:id="@+id/button2"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginBottom="5dp"

android:layout_marginTop="5dp"

android:text="openactivity" android:textColor="@android:color/background_dark"

android:textSize="18sp"

android:textStyle="bold"/>

<TextView

android:id="@+id/textView9"

android:layout_width="match_parent" android:layout_height="wrap_content"

android:layout_marginBottom="5dp"

android:background="@color/colorPrimary" android:text="internet" android:textColor="@android:color/background_light"

android:textSize="24sp"

android:textStyle="bold"/>

pg.8

MobileApplicationandDevelopment-LabManual

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"

android:layout_marginRight="50dp"

android:orientation="horizontal">

<Button

android:id="@+id/button4"

android:layout_width="160dp"

android:layout_height="wrap_content"

android:layout_marginBottom="5dp"

android:layout_marginRight="10dp"

android:text="PhoneDialer"

android:textSize="18sp"

android:textStyle="bold"/>

<Button

android:id="@+id/button3"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginBottom="5dp"

android:layout_marginLeft="10dp"

android:layout_marginRight="50dp"

android:layout_weight="0.17"

android:text="Map"

android:textSize="18sp"

android:textStyle="bold"/>

</LinearLayout>

<TextView

android:id="@+id/textView4"

android:layout_width="match_parent"

pg.9

MobileApplicationandDevelopment-LabManual

android:layout_height="44dp"

android:background="@color/colorPrimary" android:text="Passtoanotheractivity" android:textColor="@android:color/background_light"

android:textSize="24sp"

android:textStyle="bold"/>

<LinearLayout android:layout_width="match_parent"

android:layout_height="58dp"

android:layout_marginLeft="0dp"

android:orientation="horizontal">

<TextView

android:id="@+id/textView10"

android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Name"

android:textSize="24sp"

android:textStyle="bold"/>

<EditText android:id="@+id/editText"

android:layout_width="242dp"

android:layout_height="wrap_content"

android:layout_marginLeft="55dp"

android:ems="10"

android:inputType="textPersonName"/>

</LinearLayout>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

pg.10

MobileApplicationandDevelopment-LabManual

android:orientation="horizontal">

<TextView

android:id="@+id/textView11"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_weight="0.34"

android:text="Password"

android:textSize="24sp"

android:textStyle="bold"/>

<EditText

android:id="@+id/editText2"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_weight="0.61"

android:ems="10"

android:inputType="textPersonName"/>

</LinearLayout>

</LinearLayout>

</LinearLayout>

<Button

android:id="@+id/button8"

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="150dp"

android:layout_height="48dp"

android:background="@color/colorPrimary"

android:elevation="24dp"

android:text="Save"

tools:layout_editor_absoluteX="106dp"

pg.11

MobileApplicationandDevelopment-LabManual

tools:layout_editor_absoluteY="394dp"/>

</android.support.constraint.ConstraintLayout>

Layout#3

TextView:

XMLCode:

<?xmlversion="1.0"encoding="utf-8"?>

<android.support.constraint.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/

res/android"

xmlns:app="http://schemas.android.com/apk/res-

auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.thenewlogo.myapplication .MainActivity"> <LinearLayout

android:layout_width="391dp"

android:layout_height="523dp"

android:background="@color/colorPrimaryDark" android:orientation="vertical"

tools:layout_editor_absoluteX="-3dp"

tools:layout_editor_absoluteY="5dp">

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal">

</LinearLayout>

:layout_height= "wrap_content" android :orientation= "horizontal" > </ LinearLayout > pg. 12

pg.12

MobileApplicationandDevelopment-LabManual

<TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Playandexplore" android:textColor="@android:color/background_light"

android:textSize="30sp"

android:textStyle="bold"/>

<LinearLayout android:layout_width="wrap_content"

android:layout_height="117dp"

android:orientation="horizontal"

android:weightSum="3">

<ImageView

android:id="@+id/imageView5"

android:layout_width="113dp"

android:layout_height="123dp"

android:layout_marginLeft="10dp"

app:srcCompat="@drawable/aa"/>

<ImageView

android:id="@+id/imageView3"

android:layout_width="122dp"

android:layout_height="match_parent"

app:srcCompat="@drawable/bb"/>

<ImageView

android:id="@+id/imageView4"

android:layout_width="130dp"

android:layout_height="match_parent"

app:srcCompat="@drawable/cc"

pg.13

MobileApplicationandDevelopment-LabManual

android:layout_weight="5.55"/>

</LinearLayout>

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView6"

android:layout_width="183dp"

android:layout_height="138dp"

app:srcCompat="@drawable/Screenshot_5"/>

<ImageButton

android:id="@+id/imageButton5"

android:layout_width="wrap_content"

android:layout_height="134dp"

android:background="@android:color/background_dark"

app:srcCompat="@drawable/Screenshot_5"

android:layout_weight="447.53"/>

</LinearLayout>

<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"

android:weightSum="1">

<ImageView

android:id="@+id/imageView"

android:layout_width="wrap_content"

pg.14

MobileApplicationandDevelopment-LabManual

android:layout_height="wrap_content"

app:srcCompat="@drawable/ee"/>

</LinearLayout>

</LinearLayout>

</android.support.constraint.ConstraintLayout>

Layout#4

Textview:

XMLCode:

<?xmlversion="1.0"encoding="utf-8"?>

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk /res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"

tools:context="layout4.com.Main2Activity">

<LinearLayout

"layout4.com.Main2Activity" > < LinearLayout android:layout_width= "368dp" android:layout_height=

android:layout_width="368dp"

android:layout_height="495dp"

android:background="@android:color/darker_gray" android:orientation="vertical"

tools:layout_editor_absoluteX="8dp"

tools:layout_editor_absoluteY="8dp">

<LinearLayout

android:layout_width="wrap_content"

pg.15

MobileApplicationandDevelopment-LabManual

android:layout_height="wrap_content"

android:layout_marginBottom="50dp"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView2"

android:layout_width="wrap_content"

android:layout_height="115dp"

android:layout_marginLeft="135dp"

app:srcCompat="@drawable/aa"/>

</LinearLayout>

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"

android:layout_marginBottom="50dp"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView9"

android:layout_width="wrap_content"

android:layout_height="115dp"

android:layout_weight="1.35"

app:srcCompat="@drawable/cc"/>

<ImageView

android:id="@+id/imageView8"

android:layout_width="wrap_content"

android:layout_height="109dp"

android:layout_weight="1.36"

app:srcCompat="@drawable/bb"/>

</LinearLayout>

pg.16

MobileApplicationandDevelopment-LabManual

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="horizontal">

<ImageView

android:id="@+id/imageView12"

android:layout_width="wrap_content"

android:layout_height="123dp"

android:layout_weight="1"

app:srcCompat="@drawable/dd"/>

<ImageView

android:id="@+id/imageView11"

android:layout_width="wrap_content"

android:layout_height="119dp"

android:layout_weight="0.65"

app:srcCompat="@drawable/ee"/>

</LinearLayout>

</LinearLayout>

</android.support.constraint.ConstraintLayout>

LabTaskno.3

Relativelayouts

RelativeLayout:

RelativeLayoutisaviewgroupthatdisplayschildviewsinrelative

positions.Thepositionofeachviewcanbespecifiedasrelativetosibling

elements(suchastotheleft-oforbelowanotherview)orinpositions

relativetotheparentRelativeLayoutarea(suchasalignedtothebottom,

pg.17

MobileApplicationandDevelopment-LabManual

leftorcenter).

Layout#1

TextView:

XMLcode:

<?xmlversion="1.0"encoding="utf-8"?>

<RelativeLayout

encoding= "utf-8" ?> < RelativeLayout xmlns: android =

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"

tools:layout_editor_absoluteX="8dp"

tools:layout_editor_absoluteY="8dp">

<Button

pg.18

MobileApplicationandDevelopment-LabManual

android:id="@+id/button" android:layout_width="wrap_content"

android:layout_height="87dp"

android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"

android:layout_marginStart="5dp"

android:layout_marginLeft="5dp"

android:layout_marginTop="1dp"

android:background="@android:color/holo_blue_bright"

android:text="Topleft"/>

<Button

android:id="@+id/btn2"

android:layout_width="wrap_content"

android:layout_height="88dp"

android:layout_alignParentTop="true" android:layout_centerHorizontal="true"

android:layout_marginLeft="66dp"

android:layout_marginTop="0dp"

android:layout_marginRight="50dp"

android:layout_toRightOf="@id/button"

android:background="@android:color/holo_orange_dark"

android:text="Topmiddle"/>

<Button

android:id="@+id/button3"

android:layout_width="wrap_content"

android:layout_height="84dp"

android:layout_alignParentTop="true" android:layout_alignParentEnd="true" android:layout_alignParentRight="true"

android:layout_marginLeft="-23dp"

android:layout_marginTop="0dp"

pg.19

MobileApplicationandDevelopment-LabManual

android:layout_marginEnd="0dp"

android:layout_marginRight="0dp"

android:layout_toRightOf="@id/btn2"

android:background="@android:color/holo_blue_bright"

android:text="topright"/>

<Button

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="62dp"

android:layout_marginTop="350dp"

android:background="@android:color/holo_orange_dark"

android:text="Left"/>

<Button

android:id="@+id/button5"

android:layout_width="match_parent"

android:layout_height="64dp"

android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignParentBottom="true"

android:layout_marginEnd="0dp"

android:layout_marginRight="0dp"

android:layout_marginBottom="197dp"

android:background="@android:color/holo_blue_bright"

android:text="Button"/>

<Button

android:id="@+id/button6"

android:layout_width="wrap_content"

android:layout_height="75dp"

android:layout_centerInParent="true"

pg.20

MobileApplicationandDevelopment-LabManual

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:background="@android:color/holo_blue_bright"

android:text="center"/>

<Button

android:id="@+id/button7"

android:layout_width="wrap_content"

android:layout_height="58dp"

android:layout_alignTop="@+id/button4"

android:layout_alignParentEnd="true"

android:layout_marginTop="1dp"

android:layout_marginEnd="0dp"

android:Layout_marginRight="20dp"

android:background="@android:color/holo_orange_dark"

android:text="Right"/>

</RelativeLayout>

</RelativeLayout>

Layout#2

TextView:

XMLcode:

<?xmlversion="1.0"encoding="utf-8"?>

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/

res/android"

xmlns:app="http://schemas.android.com/apk/res-

auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android :layout_width= "match_parent" android :layout_height= "match_parent" pg. 21

pg.21

MobileApplicationandDevelopment-LabManual

android:background="@android:color/holo_orange_light"

tools:context=".Main2Activity">

<TextView android:id="@+id/textView" android:layout_width="match_parent"

android:layout_height="30dp"

android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"

android:layout_marginTop="0dp"

android:background="@android:color/holo_orange_dark" android:text="Relativelayoutexample"

android:textSize="24sp"/>

<EditText android:id="@+id/editText"

android:layout_width="171dp"

android:layout_height="51dp"

android:layout_alignParentStart="true" android:layout_alignParentTop="true"

android:layout_marginStart="1dp"

android:layout_marginTop="31dp"

android:background="@android:color/background_light"

android:ems="10"

android:inputType="textPersonName" android:text="Name"

android:textSize="24sp"/>

<EditText

android:id="@+id/editText2"

android:layout_width="187dp"

android:layout_height="54dp"

android:layout_alignParentStart="true"

pg.22

MobileApplicationandDevelopment-LabManual

android:layout_alignParentLeft="true" android:layout_alignParentTop="true"

android:layout_marginStart="195dp"

android:layout_marginLeft="195dp"

android:layout_marginTop="30dp"

android:background="@android:color/background_light" android:inputType="textPersonName" android:text="Address"

android:textSize="24sp"/>

<EditText

android:id="@+id/editText3"

android:layout_width="match_parent"

android:layout_height="50dp"

android:layout_marginTop="100dp"

android:background="@android:color/background_light" android:inputType="textPersonName" android:text="Subject"

android:textSize="24sp"/>

<EditText

android:id="@+id/editText4"

android:layout_width="match_parent"

android:layout_height="150dp"

android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true"

android:layout_marginBottom="185dp"

android:background="@android:color/background_light"

android:ems="10"

android:gravity="top"

android:inputType="textPersonName"

android:text="Message"

pg.23

MobileApplicationandDevelopment-LabManual

android:textAlignment="gravity"

android:textSize="24sp"/>

<Button

android:id="@+id/button2"

android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true"

android:layout_marginStart="161dp"

android:layout_marginLeft="161dp"

android:layout_marginBottom="109dp"

android:text="Submiit"/>

</RelativeLayout>

Labtaskno.4

Listeners.

AndroidEventListeners.Inandroid,EventListenerisaninterfaceintheViewclassthat

containsasinglecall-backmethod.ThesemethodswillbecalledbytheAndroidframework

whentheViewwhichisregisteredwithlisteneristriggeredbyuserinteractionwiththeitem

inUI.

OnClickListener:

setOnClickListener-Callbackwhentheviewisclicked.

OnLongClickListener:

setOnLongClickListener-Callbackforpressingandholdingaview.

pg.24

MobileApplicationandDevelopment-LabManual

Buttonlisteners:

Onclickandonlongclick

XMLcode(activity_main):

?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hellowworld"

android:textSize="32dp"

android:textAllCaps="true" android:textStyle="bold"

android:id="@+id/t1"/>

<Button

android:id="@+id/b1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Change(onclick)(onlongclick)"/>

<Button

android:id="@+id/button2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

pg.25

MobileApplicationandDevelopment-LabManual

android:text="Next(intentithlongclick)"/>

</LinearLayout>

XMLcode(activity_2main):

?xmlversion="1.0"encoding="utf-8"?>

<LinearLayout

encoding= "utf-8" ?> < LinearLayout xmlns: android =

xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"

tools:context=".Main2Activity">

<TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_weight="1"

android:text="OurCountry"

android:textSize="32dp"/>

</LinearLayout>

JavaCode:

Mainactivity:

packagecom.iqrajaved.program1;

pg.26

MobileApplicationandDevelopment-LabManual

importandroid.content.Intent;

importandroid.support.v7.app.AppCompatActivity;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.widget.Button;

importandroid.widget.TextView;

publicclassMainActivityextendsAppCompatActivity{

@Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

Buttonbtn=(Button)findViewById(R.id.b1);

Buttonbtn2=(Button)findViewById(R.id.button2);

finalTextViewtxt=(TextView)findViewById(R.id.t1);

btn.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(Viewview){ txt.setText("Pakistan");

txt.setTextSize(10);

}

});

btn.setOnLongClickListener(new

View.OnLongClickListener(){

@Override

publicbooleanonLongClick(Viewview){

txt.setText("Independentcountry");

returnfalse;

};

});

btn2.setOnLongClickListener(new

View.OnLongClickListener(){

"Independentcountry" ); returnfalse ; }; }); btn2.setOnLongClickListener( new View.OnLongClickListener(){ pg. 27
"Independentcountry" ); returnfalse ; }; }); btn2.setOnLongClickListener( new View.OnLongClickListener(){ pg. 27

pg.27

MobileApplicationandDevelopment-LabManual

@Override publicbooleanonLongClick(Viewview){

Intentopen=newIntent(MainActivity.this,Main2Activity.class);

startActivity(open);

returnfalse;

}}

}

});

Main_Activity2:

packagecom.iqrajaved.program1;

importandroid.support.v7.app.AppCompatActivity;

importandroid.os.Bundle;

publicclassMain2ActivityextendsAppCompatActivity{

@Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main2);

}

}

Edittextlistners:

OnTouch(),onKey(),addTextChange()

XMLcode:

<?xmlversion="1.0"encoding="utf-8"?>

<android.support.constraint.ConstraintLayout

xmlns:android="http://schemas.android.com/apk/res/android"

pg.28

MobileApplicationandDevelopment-LabManual

xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"

tools:layout_editor_absoluteY="81dp">

<EditText

android:id="@+id/editText3"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginStart="37dp"

android:layout_marginLeft="37dp"

android:layout_marginTop="38dp"

android:layout_marginBottom="56dp"

android:ems="10"

android:inputType="textPersonName"

app:layout_constraintBottom_toTopOf="@+id/editText4"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"/>

<EditText

android:id="@+id/editText4"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginStart="37dp"

android:layout_marginLeft="37dp"

android:layout_marginBottom="147dp"

android:ems="10"

android:inputType="textPersonName" app:layout_constraintBottom_toTopOf="@+id/textView" app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/editText3"/>

pg.29

MobileApplicationandDevelopment-LabManual

<TextView android:id="@+id/textView" android:layout_width="wrap_content"

android:layout_height="0dp"

android:layout_marginStart="16dp"

android:layout_marginLeft="16dp"

android:layout_marginBottom="68dp"

android:text="et1containssetOnKeyListeneraswellasaddTextChangedListener

whileet2conainssetOnTouchListener"

android:textSize="18sp"

app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/editText4"/>

</android.support.constraint.ConstraintLayout>

Javacode:

packagecom.iqrajaved.program2;

importandroid.support.v7.app.AppCompatActivity;

importandroid.os.Bundle;

importandroid.text.Editable;

importandroid.text.TextWatcher;

importandroid.view.KeyEvent;

importandroid.view.MotionEvent;

importandroid.view.View;

importandroid.widget.Button;

importandroid.widget.EditText;

publicclassMainActivityextendsAppCompatActivity{

@Override

protectedvoidonCreate(BundlesavedInstanceState){

pg.30

MobileApplicationandDevelopment-LabManual

super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

finalEditTextet2=(EditText)findViewById(R.id.editText4);

finalEditTextet1=(EditText)findViewById(R.id.editText3);

et2.setOnTouchListener(newView.OnTouchListener(){

@Override publicbooleanonTouch(Viewview,MotionEventmotionEvent){

et2.setText(et1.getText().toString());

returntrue;

}

});

et1.setOnKeyListener(newView.OnKeyListener(){

@Override publicbooleanonKey(Viewview,inti,KeyEventkeyEvent){ if(keyEvent.getAction()==KeyEvent.ACTION_UP){ if(i==KeyEvent.KEYCODE_ENTER)

et2.setText("youpressedenter");}

elseif(i==KeyEvent.KEYCODE_0)

{et2.setText("youenteredzero");

}

returnfalse;

}

});

et1.addTextChangedListener(newTextWatcher(){

@Override

publicvoidbeforeTextChanged(CharSequences,intstart,intcount,intafter){

}

@Override

publicvoidonTextChanged(CharSequences,intstart,intbefore,intcount){

pg.31

MobileApplicationandDevelopment-LabManual

et2.setText(s.toString());

}

@Override

publicvoidafterTextChanged(Editables){

}

});

}}

Labtaskno.5

CreateasimplecalculatorinAndroid

Layoutdesign:

Designview:

XMLcode:

<?xmlversion="1.0"encoding="utf-8"?>

<android.support.constraint.ConstraintLayout

?> < android.support.constraint.ConstraintLayout xmlns:android=

xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"

tools:layout_editor_absoluteY="81dp">

pg.32

MobileApplicationandDevelopment-LabManual

<EditText

android:id="@+id/editText3"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:ems="10"

android:inputType="textPersonName"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"/>

<EditText

android:id="@+id/editText4"

android:layout_width="match_parent" android:layout_height="wrap_content"

android:layout_marginTop="7dp"

android:ems="10"

android:inputType="textPersonName"

app:layout_constraintEnd_toEndOf="@+id/btn2"

app:layout_constraintStart_toEndOf="@+id/btn2"

app:layout_constraintTop_toBottomOf="@+id/editText3"/>

<Button

android:id="@+id/btn1"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginStart="4dp"

android:layout_marginLeft="4dp"

android:layout_marginEnd="15dp"

android:layout_marginRight="15dp"

android:text="1"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintBaseline_toBaselineOf="@+id/btn2"

app:layout_constraintEnd_toStartOf="@+id/btn2"

pg.33

MobileApplicationandDevelopment-LabManual

app:layout_constraintHorizontal_chainStyle="packed"

app:layout_constraintStart_toStartOf="parent"/>

<Button

android:id="@+id/btn2"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginEnd="14dp"

android:layout_marginRight="14dp"

android:text="2"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintBaseline_toBaselineOf="@+id/btn3"

app:layout_constraintEnd_toStartOf="@+id/btn3"

app:layout_constraintStart_toEndOf="@+id/btn1"/>

<Button

android:id="@+id/btn3"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginTop="33dp"

android:layout_marginEnd="7dp"

android:layout_marginRight="7dp"

android:text="3"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintEnd_toStartOf="@+id/btn4"

app:layout_constraintStart_toEndOf="@+id/btn2"

app:layout_constraintTop_toBottomOf="@+id/editText4"/>

<Button

android:id="@+id/btn4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

pg.34

MobileApplicationandDevelopment-LabManual

android:text="4"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintBaseline_toBaselineOf="@+id/btn3"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toEndOf="@+id/btn3"/>

<Button

android:id="@+id/btn5"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginStart="4dp"

android:layout_marginLeft="4dp"

android:layout_marginEnd="15dp"

android:layout_marginRight="15dp"

android:text="5"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintBaseline_toBaselineOf="@+id/btn6"

app:layout_constraintEnd_toStartOf="@+id/btn6"

app:layout_constraintHorizontal_chainStyle="packed"

app:layout_constraintStart_toStartOf="parent"/>

<Button

android:id="@+id/btn6"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginEnd="14dp"

android:layout_marginRight="14dp"

android:text="6"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintBaseline_toBaselineOf="@+id/btn7"

app:layout_constraintEnd_toStartOf="@+id/btn7"

pg.35

MobileApplicationandDevelopment-LabManual

app:layout_constraintStart_toEndOf="@+id/btn5"/>

<Button

android:id="@+id/btn7"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginTop="28dp"

android:layout_marginEnd="7dp"

android:layout_marginRight="7dp"

android:text="7"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintEnd_toStartOf="@+id/btn8"

app:layout_constraintStart_toEndOf="@+id/btn6"

app:layout_constraintTop_toBottomOf="@+id/btn3"/>

<Button

android:id="@+id/btn8"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:text="8"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintBaseline_toBaselineOf="@+id/btn7"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toEndOf="@+id/btn7"/>

<Button

android:id="@+id/btn9"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:text="9"

android:textSize="18sp"

android:textStyle="bold"

pg.36

MobileApplicationandDevelopment-LabManual

app:layout_constraintBaseline_toBaselineOf="@+id/btn0"

app:layout_constraintStart_toStartOf="parent"/>

<Button

android:id="@+id/btn0"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginStart="15dp"

android:layout_marginLeft="15dp"

android:layout_marginBottom="26dp"

android:text="0"

android:textSize="18sp"

android:textStyle="bold" app:layout_constraintBottom_toTopOf="@+id/bsub"

app:layout_constraintStart_toEndOf="@+id/btn9"/>

<Button android:id="@+id/badd" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginStart="16dp"

android:layout_marginLeft="16dp"

android:layout_marginBottom="27dp"

android:text="+"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintBottom_toTopOf="@+id/bdiv"

app:layout_constraintStart_toStartOf="parent"/>

<Button android:id="@+id/bsub" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginStart="33dp"

pg.37

MobileApplicationandDevelopment-LabManual

android:layout_marginLeft="33dp"

android:layout_marginBottom="9dp"

android:text="-"

android:textSize="18sp"

android:textStyle="bold" app:layout_constraintBottom_toBottomOf="@+id/badd"

app:layout_constraintStart_toStartOf="@+id/btn0"/>

<Button android:id="@+id/bdiv" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginStart="16dp"

android:layout_marginLeft="16dp"

android:layout_marginBottom="16dp"

android:text="/"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintStart_toStartOf="parent"/>

<Button android:id="@+id/bmul" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginEnd="37dp"

android:layout_marginRight="37dp"

android:text="x"

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintBaseline_toBaselineOf="@+id/bsub"

app:layout_constraintEnd_toEndOf="parent"/>

<Button

pg.38

MobileApplicationandDevelopment-LabManual

android:id="@+id/bdot" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginStart="32dp"

android:layout_marginLeft="32dp"

android:layout_marginBottom="16dp"

android:text="."

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintStart_toEndOf="@+id/bdiv"/>

<Button android:id="@+id/bequ" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginEnd="37dp"

android:layout_marginRight="37dp"

android:layout_marginBottom="16dp"

android:text="="

android:textSize="18sp"

android:textStyle="bold"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"/>

<Button android:id="@+id/btnc" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginStart="21dp"

android:layout_marginLeft="21dp"

android:text="clear"

android:textSize="18sp"

android:textStyle="bold"

pg.39

MobileApplicationandDevelopment-LabManual

app:layout_constraintBaseline_toBaselineOf="@+id/btn0"

app:layout_constraintStart_toEndOf="@+id/btn0"/>

</android.support.constraint.ConstraintLayout>

JAVAcode:

packagecom.iqrajaved.calculator;

importandroid.support.v7.app.AppCompatActivity;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.widget.EditText;

importandroid.widget.Button;

importjava.util.regex.Pattern;

publicclassMainActivityextendsAppCompatActivity{

Stringop;

@Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

Buttonb1=(Button)findViewById(R.id.btn1);

Buttonb2=(Button)findViewById(R.id.btn2);

Buttonb3=(Button)findViewById(R.id.btn3);

Buttonb4=(Button)findViewById(R.id.btn4);

Buttonb5=(Button)findViewById(R.id.btn5);

Buttonb6=(Button)findViewById(R.id.btn6);

Buttonb7=(Button)findViewById(R.id.btn7);

Buttonb8=(Button)findViewById(R.id.btn8);

Buttonb9=(Button)findViewById(R.id.btn9);

Buttonb0=(Button)findViewById(R.id.btn0);

Buttonba=(Button)findViewById(R.id.badd);

pg.40

MobileApplicationandDevelopment-LabManual

Buttonbs=(Button)findViewById(R.id.bsub);

Buttonbm=(Button)findViewById(R.id.bmul);

Buttonbd=(Button)findViewById(R.id.bdiv);

Buttonbdo=(Button)findViewById(R.id.bdot);

Buttonbe=(Button)findViewById(R.id.bequ);

Buttonbc=(Button)findViewById(R.id.btnc);

//Buttonbsqt=(Button)findViewById(R.id.bsq);

finalEditTexttxt1=(EditText)findViewById(R.id.editText3);

finalEditTexttxt2=(EditText)findViewById(R.id.editText4);

bdo.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(Viewview){

txt1.setText(txt1.getText().toString()+".");

}

});

b1.setOnClickListener(newView.OnClickListener(){

@Override publicvoidonClick(Viewview){

txt1.setText(txt1.getText().toString()+"1");

}

});

b2.setOnClickListener(newView.OnClickListener(){

@Override publicvoidonClick(Viewview){

txt1.setText(txt1.getText().toString()+"2");

}

});

b3.setOnClickListener(newView.OnClickListener(){

@Override publicvoidonClick(Viewview){

txt1.setText(txt1.getText().toString()+"3");

pg.41

MobileApplicationandDevelopment-LabManual

}

});

b4.setOnClickListener(newView.OnClickListener(){

@Override publicvoidonClick(Viewview){

txt1.setText(txt1.getText().toString()+"4");

}

});

b5.setOnClickListener(newView.OnClickListener(){

@Override publicvoidonClick(Viewview){

txt1.setText(txt1.getText().toString()+"5");

}

});

b6.setOnClickListener(newView.OnClickListener(){

@Override publicvoidonClick(Viewview){

txt1.setText(txt1.getText().toString()+"6");

}

});

b7.setOnClickListener(newView.OnClickListener(){

@Override publicvoidonClick(Viewview){

txt1.setText(txt1.getText().toString()+"7");

}

});

b8.setOnClickListener(newView.OnClickListener(){

@Override publicvoidonClick(Viewview){

txt1.setText(txt1.getText().toString()+"8");

pg.42

MobileApplicationandDevelopment-LabManual

}

});

b9.setOnClickListener(newView.OnClickListener(){

@Override publicvoidonClick(Viewview){

txt1.setText(txt1.getText().toString()+"9");

}

});

b0.setOnClickListener(newView.OnClickListener(){

@Override publicvoidonClick(Viewview){

txt1.setText(txt1.getText().toString()+"0");

}

}); ba.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(Viewview){ op="+";

txt1.setText(txt1.getText().toString()+"+");

}

});

ba.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(Viewview){ op="+";

txt1.setText(txt1.getText().toString()+"+");

}

}); bs.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(Viewview){ op="-";

txt1.setText(txt1.getText().toString()+"-");

pg.43

MobileApplicationandDevelopment-LabManual

}

}); bm.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(Viewview){ op="x";

txt1.setText(txt1.getText().toString()+"x");

}

}); bd.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(Viewview){ op="/";

txt1.setText(txt1.getText().toString()+"/");

}

}); bc.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(Viewview){

txt1.setText("");

txt2.setText(null);

}

}); be.setOnClickListener(newView.OnClickListener(){ @Override publicvoidonClick(Viewview){

Strings1=txt1.getText().toString();

Doubleval1,val2,res;

String[]s2=s1.split(Pattern.quote(op));

val1=Double.parseDouble(s2[0]);

val2=Double.parseDouble(s2[1]);

if(op=="+"){

res=val1+val2;

txt2.setText(Double.toString(res));

pg.44

MobileApplicationandDevelopment-LabManual

}

elseif(op=="-"){

res=val1-val2;

txt2.setText(Double.toString(res));

}

elseif(op=="x"){

res=val1*val2;

txt2.setText(Double.toString(res));

}

elseif(op=="/"){

res=val1/val2;

txt2.setText(Double.toString(res));

}

}

});}}

OUTPUT:

Division:

txt2.setText(Double.toString(res)); } } });}} OUTPUT: Division: Multiplication: Subtraction: Addition: pg. 45

Multiplication:

txt2.setText(Double.toString(res)); } } });}} OUTPUT: Division: Multiplication: Subtraction: Addition: pg. 45

Subtraction:

Addition:

pg.45

MobileApplicationandDevelopment-LabManual

MobileApplicationandDevelopment-LabManual LabTaskno.6 Simpleweightandcurrencyconverterinandroid ActivitycurrencyXmlCode:
MobileApplicationandDevelopment-LabManual LabTaskno.6 Simpleweightandcurrencyconverterinandroid ActivitycurrencyXmlCode:
MobileApplicationandDevelopment-LabManual LabTaskno.6 Simpleweightandcurrencyconverterinandroid ActivitycurrencyXmlCode:

LabTaskno.6

Simpleweightandcurrencyconverterinandroid

ActivitycurrencyXmlCode:

<?xmlversion="1.0"encoding="utf-8"?>

pg.46

MobileApplicationandDevelopment-LabManual

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".Currency" android:background="@color/ty"> <EditText

android:id="@+id/t1"

android:layout_width="match_parent"

android:layout_height="60dp"

android:hint="EnterCurrency"

android:textSize="20sp"

android:layout_margin="30dp"

/> <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginLeft="25dp">

<RadioButton

android:id="@+id/r1"

android:layout_width="wrap_content"

android:layout_height="40dp"

android:text="RupeestoRiyal"

android:textSize="20sp"/>

<RadioButton

android:id="@+id/r2"

android:layout_width="wrap_content"

android:layout_height="40dp"

android:text="RiyaltoRupees"

pg.47

MobileApplicationandDevelopment-LabManual

android:textSize="20sp"/>

<RadioButton

android:id="@+id/r3"

android:layout_width="wrap_content"

android:layout_height="40dp"

android:text="DharamtoRupees"

android:textSize="20sp"/>

<RadioButton

android:id="@+id/r4"

android:layout_width="wrap_content"

android:layout_height="40dp"

android:text="RupeestoDaham"

android:textSize="20sp"/>

</RadioGroup> <Button

android:id="@+id/b1"

android:layout_width="match_parent"

android:layout_height="60dp"

android:layout_marginTop="30dp"

android:text="Convert"

android:layout_margin="30dp"

android:textSize="20sp"

android:background="@color/yy" android:textColor="#fff" /> <EditText

android:id="@+id/t2"

android:layout_width="match_parent"

android:layout_height="60dp"

android:hint="ConvertedCurrency"

pg.48

MobileApplicationandDevelopment-LabManual

android:textSize="20sp"

android:layout_marginLeft="30dp"

android:layout_marginRight="30dp"

/>

</LinearLayout>

ActivityweightXml:-

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayout

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context=".Weight"

android:background="@color/colorAccent">

<EditText

android:id="@+id/t1"

android:layout_width="match_parent"

android:layout_height="60dp"

android:hint="EnterWeight"

android:textSize="20sp"

android:layout_margin="30dp"

/>

pg.49

MobileApplicationandDevelopment-LabManual

<RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginLeft="25dp">

<RadioButton

android:id="@+id/r1"

android:layout_width="wrap_content"

android:layout_height="40dp"

android:text="KilogramstoGrams"

android:textSize="20sp"/>

<RadioButton

android:id="@+id/r2"