We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
pel programming {BBA (CA): Som. VI} 2.29
° Activity, Intent and Layout
ndroidiide"@rid/txtPassword”
indroid:inputTypes"textPassword"/>
ptableRow>
‘rableROW?
qrextview />
checkBox. android: id="@+4d/chkRemenberPassword”
jndroid: 1ayout_width="#411_parent™
android: Layout_height="wrap_content”
android: text="RememberPassword"/>
«/TableRow>
cTableRow>
veteg inv
+ Fig, 2.20 shows how the precedi
Fig, 220 preceding code appears when rendered on the Android
@)
Fig. 2.20: TableLayout Screen.
Bs GridLayout
ectangular grid.
F Alayout that places its children in ar
The grid items are not necessarily predetermined but they automatically inserted t
‘0
the layout using a Listadapter.PR aosaheb Parad
Androld Programming {BBA (CA) : Sem. VI] 2.30 Activity, Intent and tayay
* A GridView is a type of AdapterView that displays items in a two-dimensiong
Scrolling grid (rows & columns). Items are inserted into this grid layout from ;
database or from an array, The adapter is used for displaying this data, setAdapter
method is used to join the adapter with GridView,
Fig. 2.21: GridLayout in Android
+ XMLAttributes of GridView:
1. android:numColumns: This attribute of GridView will be used to decide the
number of columns that are to be displayed in Grid.
2. android:horizontalspacing: This attribute is used to define the spacing betweer
two columns of GridView.
3. android:verticalspacing: This attribute is used to specify the spacing between
two rows of GridView.
+ Forimplementing the GridLayout, you need to follow the below steps nicely.
Step1 : Goahead, start your Android Studio and click on create a new project.
Step2: Select Empty Activity and then provide a name to your application.
Step3 : Now, open your activity_main.xml and paste in the code below.
<2xml_version="1.0" encoding="utf-8"?>
res >
I layout > activity_main.xml and add the below
code to that file. Below is the code for the activity_main.xml file.
<[Link]..wid,
get .ConstraintLayout
indroid=
“[Link]
Pp: “http: //[Link]/apk/res-auto”
‘001: “http: //schemas android. com/tools"
android: layout_width: “match_parent"
android: layout_height="match_parent”
tools:context=".MyActivity">
[Link] .widget .ConstraintLayout>
Gaeik
Kamil Khan
Fig. 2.23: Constraint LayoutAndroid Programming [BBA (CA) : Sem. VI] 234 ‘Activity Intent and Layou,
FrameLayout
. The FrameLayout layout is a placeholder on screen that you can use to display a
single view. Views that you add to a FrameLayout are always anchored to the top left
of the layout.
ean
+ Consider the following content in [Link]:
<2xml version="1.0" encoding="utf-8"?>
canageview
android: “@mipmap/butterfly"
android: layout_width="
android: Layout_height=
e/FrameLayout>
rap_content"
wrap_content"/>
«/relativeLayout>
Here, you have a FrameLayout within a RelativeLa ithi:
; yout. Within the FrameLayout, you
embed an ImageView. The Ulis shown in Fig. 2.25. you
Fig, 2.25: FrameLayout within RelativeLayout
If you add another view (such as a Button view) within the FrameLayout, the view
overlaps the previous view (See Fig. 3.26)
“wrap_content"
ayout_height='
android:text="Hello, Android!”
android: layout_alignParentTop="true"
"wrap_content™ivity, Intent
periraid Programming [BBA (CA) : Sem. VO} 2.36 Activity, Intent and Lay,
leyout_glignParentStart="true">
yout
rap_content"
slayout_width=
‘wrep_content”
:leyout_elignStert="@+id/1b1Comments”
: layout_below="@+id/1b1Comments"
layout_centerHorizontal="true">
layout,
android: src="@nipmap/butterfly”
android: leyout_width="wrap_content”
android: leyout_height="wrap_content"/>
layout_width="124dp"
android: leyout_height="wrap_content”
android:text="PrintPictur
|
|
|
|
A
Fi
Fig. 2.26: Overlappin,
, ig Of FrameLay
EEX] scrotview oat
4 i
Space than tj
Linearlayout ild view or Views; he physical display. The
+ In Scrottyi, Toup, which normally is #
lew a pri +
ld view, group that contains one otherniold Programming [BBA (CA): Sem, vi
a
2.37
Activity, Intent and Layout
Scroll up to see
bottorn view.
is visible,
i viible it you
roll ony more,
Fig. 2.27: absoluteLayout in Android
+ The following [Link] content she
which is contains some Button and E
+ If you load the preceding co
what's shown in Fig. 2.28.
de on the Android emulator, you see something like
Fig. ei
‘ig. 2.28: AbsoluteLayout Screen-
ramming [BBA (CA) : Sem. VI
anaroid Pro en) Activity, Intent and Layout
gecause the EditText automatically gets the focus, it fills up the entire activity (as the
height was set to 600dp). To prevent it from getting the foeus, add the following two
polded attributes to the, *
qineartayout> element:
cLinearLayout
android: layout_width="#i1l_parent”
android: 1ayout_heigh
android:orientation="vertical"
android: focusable="true"
android: focusableTnTouchMode="true">
Now you are able to view the buttons and scroll through the list of views
(Gee Fig. 2.29).
‘wrap_content"
Fig. 2.29: ScrollView with LinearLayout
ht want EditText to automatically get the focus, but you do not
yyboard) to appear automatically (which happens on a
keyboard from appearing, add the following bolded
the [Link] file:
* Sometimes you mig!
want the soft input panel (Ke!
Teal device), To prevent the
attribute to the element in
cactivity
android: 1abel="@string/app_name”
-LayoutsActivity"
android: name='Android Programming [BBA (CA) : Sem. VI] 2.40
Activity, Intent and Layou,
jputMode="stateHidden™>
‘[Link]" />
ory android:nane="android. [Link]"/>
at-Filter>
Eure ts
Y
Y
\
Y
\
The Android activity life cycle defines the states or events that an activity goes
through from its creation until its end, The activity monitors and reacts to these
events by executing methods that override the activity class methods for each
event.
The intent generally consists of activities to be done, the parameter over which
this activity is to be performed and the application to perform this action.
Intents can be either explicit or implicit. An explicit intent calls a specific service
or activity explicitly; whereas an implicit intent just gives the definition of the
required service.
An Intent object is a bundle of information which is used by the component that
Teceives the intent as well as information used by the Android system. An intent
filter is an expression in an app's manifest file that specifies the type of intents
that the component would like to receive.
Various methods of Activity life cycle includes onCreate(), onStart(), onResume(),
onPause(), onStop(), onDestroy() and onRestart(.
Intents are asynchronous messages which allow application
components to
Feduest functionality from other Android components,
automatically by Android, whi
element.