0% found this document useful (0 votes)
121 views32 pages

U:3 Android Activities & GUI Design Concepts

The document provides an overview of Android activities, GUI design concepts, and UI controls. It discusses activity lifecycles, creating activities through the manifest file or programmatically, and using intents to navigate between activities. It also describes common layouts like linear, relative, grid and frame layouts. Finally, it covers basic UI controls in Android like textviews, edittexts, buttons, toggles and images.

Uploaded by

Anchal Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views32 pages

U:3 Android Activities & GUI Design Concepts

The document provides an overview of Android activities, GUI design concepts, and UI controls. It discusses activity lifecycles, creating activities through the manifest file or programmatically, and using intents to navigate between activities. It also describes common layouts like linear, relative, grid and frame layouts. Finally, it covers basic UI controls in Android like textviews, edittexts, buttons, toggles and images.

Uploaded by

Anchal Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

UNIT:3

Android activities & GUI


1
design concepts
SYLLABUS
 3.1 Design criteria for Android Application : Hardware
Design Consideration, Design Demands For Android
application, Intent, Activity, Activity Lifecycle and
Manifest
 3.2 Creating Application and new Activities

 3.3 Simple UI -Layouts and Layout properties


:Introduction to Android UI Design, Introducing
Layouts
 3.4 XML Introduction to GUI objects viz.: Push Button ,
Text / Labels , EditText, ToggleButton , Padding

2
3.1 DESIGN CRITERIA FOR ANDROID
APPLICATION
 Hardware Design Consideration
 Compared to desktop or laptop computers, mobile
devices have relatively:
 Low processing power

 Limited RAM

 Limited Permanent storage capacity

 Small screens with low resolution

3
DESIGN DEMANDS FOR ANDROID
APPLICATION
 While developing an android Application for
mobile devices we need to consider following
design demands in mind:
 It should be fast & efficient.

 It should use less storage as possible

 It should present consistent UI for all devices.

4
3.1.1 ACTIVITY AND ACTIVITY LIFE
CYCLE
 Activity:
 An activity represents a single screen with a user
interface.
 For example, an email application might have
one activity that shows a list of new emails,
another activity to compose an email, and
another activity for reading emails.

5
 If you have worked with C, C++ or Java
programming language then you must have seen
that your program starts from main() function.
 Very similar way, Android system initiates its
program with in an Activity starting with a call on
onCreate() callback method.

6
ACTIVITY LIFE CYCLE OF ANDROID

7
CALLBACK METHODS
 onStart(): Called when the activity becomes visible to
the user
 onResume(): Called when the activity starts
interacting with the user
 onPause(): Called when the current activity is being
paused and the previous activity is being resumed
 onStop(): Called when the activity is no longer visible
to the user
 onDestroy(): Called before the activity is destroyed by
the system
 onRestart(): Called when the activity has been stopped
and is restarting again 8
3.2 CREATING APPLICATION AND NEW
ACTIVITIES

 When we create a simple Android Application the


first Activity will be Automatically created.
 An Activity can be created using three different
ways.
 Through AndroidManifest.xml file

 Programmatically create

 Using Menubar

9
3.2.1 INTENT
 Intent provides navigation between application
components.
 Types of Intents

1. Explicit Intents
2. Implicit Intents

10
1. EXPLICIT INTENTS
 These intents designate the target component by its
name and they are typically used for application-internal
messages - such as an activity starting a subordinate
service or launching a sister activity.

 For Example:
// Explicit Intent by specifying its class name
Intent i = new Intent(this, TargetActivity.class);
i.putExtra("Key1", "ABC");
i.putExtra("Key2", "123");
// Starts TargetActivity
startActivity(i); 11
2. IMPLICIT INTENTS
 These intents do not name a target and the field for the
component name is left blank. Implicit intents are often
used to activate components in other applications.
 For Example:

// Implicit Intent by specifying a URL


Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.example.com"));
// Starts Implicit Activity
startActivity(i);

12
The target component which receives the intent can use
the getExtras() method to get the extra data sent by
the source component. For example:
// Get bundle object at appropriate place in your code
Bundle extras = getIntent().getExtras();

// Extract data using passed keys


String value1 = extras.getString("Key1");
String value2 = extras.getString("Key2");

13
3.2.2 MANIFEST FILE
 The AndroidManifest.xml file contains detailed
configuration information for your application.
 Manifest file structure

 Here is an example of the manifest file

 <?xml version=”1.0” encoding=”utf-8” ?>

 <manifest>

 xmlns:android="http://schemas.android.com/apk/res/an
droid"
</manifest>

14
3.3 SIMPLE UI -LAYOUTS AND
LAYOUT PROPERTIES
 Linear Layout
It aligns all children in a single direction,
vertically or horizontally.
 Relative Layout

It displays child views in relative positions.


 Table Layout

It groups views into rows and columns.


 Absolute Layout

Absolute Layout enables you to specify the exact


location of its children.
15
 Frame Layout
The FrameLayout is a placeholder on screen that
you can use to display a single view.
 GridView

GridView is a ViewGroup that displays items in a


two-dimensional, scrollable grid

16
LAYOUT ATTRIBUTES

 Each layout has a set of attributes which define the


visual properties of that layout. There are few common
attributes among all the layouts and their are other
attributes which are specific to that layout. Following
are common attributes and will be applied to all the
layouts:

17
1. LINEARLAYOUT
 LinearLayout is a view group that aligns all
children in a single direction, vertically or
horizontally.

18
Example
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/an
droid" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a Button" />
</LinearLayout>
19
2. RELATIVELAYOUT
 RelativeLayout allows to position the widget
relative to each other. This can be used for complex
layouts.
 A simple usage for RelativeLayout is if you want to
center a single component. Just add one component
to the RelativeLayout and set
the android:layout_centerInParentattribute to true.

20
Example
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/an
droid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/> 21
</RelativeLayout>
3. GRIDLAYOUT
 GridLayout was introduced with Android 4.0. This
layout allows you to organize a view into a Grid.
GridLayout separates its drawing area into: rows,
columns, and cells.
 You can specify how many columns you want to define
for each View, in which row and column it should be
placed as well as how many columns and rows it should
use.
 If not specified, GridLayout uses defaults, e.g., one
column, one row and the position of a Viewdepends on
the order of the declaration of the Views.

22
4. FRAMELAYOUT
 FrameLayout is a layout manager which draws
all child elements on top of each other. This
allows to create nice visual effects.

23
3.4 XML INTRODUCTION TO GUI OBJECTS :
UI CONTROLS (VIEWS) IN ANDROID
 List of UI controls:

 TextView(Text / Labels)
 EditText

 Push Button

 ToggleButton

 ImageButton

 CheckBox

 RadioButton

 RadioGroup
24
 TextView

-It is a view which is used to display text to the


user.
 EditText

-A subclass of the TextView view that allows users


to edit its text content
 Button(push button)

-It is a push-button that can be pressed, or clicked,


by the user to perform an action.
 Toggle button

-It is an on/off button with a light indicator.


-It displays checked/unchecked states using a light
25
indicator.
 Image Button
-It is similar to the Button view, except that it also
displays an image
 Checkbox

-A special type of button that has two states: checked


or unchecked
-You should use checkboxes when presenting users
with a group of selectable options that are not
mutually exclusive.

26
 RadioButton
RadioGroup and RadioButton :-
-The RadioButton has two states: either checked or
unchecked.
-A RadioGroup is used to group together one or more
RadioButton views, thereby allowing only one
RadioButton to be checked within the RadioGroup.

27
1. TEXTVIEW EXAMPLE
<LinearLayout >
<TextView android:id="@+id/text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a TextView" />

</LinearLayout>

28
2. BUTTON (PUSH BUTTON) EXAMPLE
<LinearLayout
xmlns:android="http://schemas.android.com/apk/re
s/android" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a Button" />
</LinearLayout>
29
3. TOGGLEBUTTON

 It is an on/off button with a light indicator.


 It displays checked/unchecked states using a light
indicator.

Example
<ToggleButton
android:id=”@+id/toggle1”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />

30
QUESTION BANK
 Explain activity life cycle with diagram.
 Explain android manifest in brief.

 Write a short note on layouts.

 Explain linear layout with an example.

 Explain relative layout with an example.

 Define following attributes:

Layout weight
Weight sum
Padding
Margin 31
CONTINUE…
 What is Intent ? Explain with example.
 Write short note android widget.

 Explain Button & Text field with example.

 Explain checkbox widget with example.

 Write short note Toggle button.

32

You might also like