100% found this document useful (1 vote)
383 views39 pages

MCAD - Unit 3

The document discusses Android activities, GUI design, and layouts. It describes the activity lifecycle and methods like onCreate(), onStart(), onResume(), etc. It also covers different Android layouts like FrameLayout and LinearLayout. FrameLayout is used to hold a single child view, while LinearLayout aligns children vertically or horizontally. The document also discusses intents, passing data between activities, and the Android project framework.

Uploaded by

rutvi sheth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
383 views39 pages

MCAD - Unit 3

The document discusses Android activities, GUI design, and layouts. It describes the activity lifecycle and methods like onCreate(), onStart(), onResume(), etc. It also covers different Android layouts like FrameLayout and LinearLayout. FrameLayout is used to hold a single child view, while LinearLayout aligns children vertically or horizontally. The document also discusses intents, passing data between activities, and the Android project framework.

Uploaded by

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

Unit-3

Android Activities and GUI Design


1
Concepts
CO2: Create android application using different android layout and GUI objects.

06/03/2023
2 DESIGN CRITERIA FOR ANDROID
APPLICATION
 Hardware Design Consideration
 Compared to desktop or laptop computers, mobile devices have relatively:
1. Low processing power
2. Limited RAM
3. Limited Permanent storage capacity
4. Small screens with low resolution
5. Limited Battery Life

06/03/2023
3 DESIGN DEMANDS FOR ANDROID
APPLICATION
 While developing an android Application for mobile devices we need to consider
following design demands in mind:
1. It should be fast & efficient.
2. It should use less storage as possible
3. It should present consistent UI for all devices.

06/03/2023
4 Activity & Activity Life Cycle

 In Android, an activity is a component of the application that represents a single screen


with a user interface.
 It can be used to perform tasks, show user interfaces, and receive user input.
 The activity life cycle refers to the series of states that an activity goes through as it is
created, used, and destroyed.
 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.

06/03/2023
5 Activity Life Cycle

06/03/2023
6 Activity Life Cycle Methods
Method Description

This method is called when the activity is first created. It is used to


onCreate() initialize the activity, such as setting up the user interface and initializing
data structures.

This method is called when the activity becomes visible to the user. It is
onStart() used to initialize any components that need to be started when the activity
is visible.

This method is called when the activity is in the foreground and has the
onResume() user focus. It is used to start or resume any actions that were paused in the
onPause() method.

06/03/2023
7 Activity Life Cycle Methods
Method Description
This method is called when the activity loses the user focus and becomes
onPause() partially visible. It is used to pause any ongoing actions or release resources
that are not needed when the activity is not in the foreground.
This method is called when the activity is no longer visible to the user. It is
onStop() used to release any resources that are not needed when the activity is not
visible.
This method is called when the activity is being destroyed. It is used to
onDestroy()
release any resources that were allocated during the activity's life cycle.
This method is called when the activity after the activity has been stopped
onRestart() but before it is started again. It is called when the user navigates back to the
activity from the stopped state.

06/03/2023
Android project framework
8

 AndroidManifest.xml: This file contains essential information about the application, such
as its package name, version, permissions, and activities. In Eclipse, this file is located in
the project's root directory.
 Java source code: This is the code that provides the logic and functionality for the
application. In Eclipse, the Java source code is located in the /src directory of the project.
 Resources: Resources include all the non-code assets used by the application, such as
layouts, images, strings, and other resources. In Eclipse, these resources are stored in the
/res directory of the project.
 Project properties: The project properties contain the project's settings, such as the build
target, Java compiler, and other project-specific settings. In Eclipse, these properties can be
accessed by selecting "Project" > "Properties" from the menu bar.
 Libraries: Libraries are pre-built code modules that can be included in the application to
provide additional functionality. In Eclipse, libraries can be added to the project by
selecting "Project" > "Properties" > "Java Build Path" from the menu bar.

06/03/2023
Intent and its type
9

 In Android, an Intent is an object that represents an action to be performed, such as starting


a new activity, broadcasting a message, or performing a service.
 It is a messaging object that can be used to pass information between different components
of an application, as well as between different applications.
 There are two types of Intents in Android:
1. Explicit Intent: An explicit Intent is used to start a specific component, such as an Activity or
Service, within the same application. It is typically used to start a new Activity with a specified
class name.
Code:
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("key", "value");
// Starts TargetActivity
startActivity(intent);

06/03/2023
Intent and its type
10

 putExtra() method is used to add data to an Intent object before it is passed to another
component. It takes two arguments: a key and a value. The key is a string that identifies the data
being passed, and the value is the actual data being passed.
 getExtras() is a method in the Android Intent class that is used to retrieve all of the extras that
were added to an Intent object using the putExtra() method. The extras are returned as a Bundle
object, which is a collection of key-value pairs.

Bundle extras = getIntent().getExtras();


if (extras != null) {
String value = extras.getString("key");
}

06/03/2023
Intent and its type
11

2. Implicit Intent: An implicit Intent is used to request an action from another application, or to perform
an action that does not require a specific component. It is typically used to start an activity that can
handle a certain type of data, such as opening a web page or sending an email.

Code:
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(intent);

 There are also several predefined actions and categories that can be used with Intents, such as
ACTION_VIEW, ACTION_SEND that can be used to specify the type of action that is being
requested, and the type of data that is being passed between components.

06/03/2023
12 Different Layouts in Android-FrameLayout
 In Android, FrameLayout is a ViewGroup subclass that is used to specify a single view
that fills the entire layout container.
 It is generally used to hold a single child view, such as a single image, icon or button.
 Some of the important attributes of FrameLayout in Android are:
 layout_width and layout_height: These attributes are used to specify the width and height
of the FrameLayout, either in pixels or as a dimension or a fraction of the parent view.
 gravity: This attribute is used to specify the gravity of the child view within the
FrameLayout. For example, setting gravity="center" will center the child view horizontally
and vertically within the FrameLayout.
 foreground: This attribute is used to specify a drawable or color that should be drawn in
front of the child view. This can be used to add a border or highlight to the child view.
 background: This attribute is used to specify a drawable or color that should be used as the
background of the FrameLayout.

06/03/2023
13 Different Layouts in Android Linear Layout
 Android LinearLayout is a view group that aligns all children in
either vertically or horizontally.

06/03/2023
14 Different Layouts in Android Linear Layout
 android:id: This is the ID which uniquely identifies the layout.

 android:gravity: This specifies how an object should position its content, on both the X and
Y axes. Possible values are top, bottom, left, right, center, center_vertical,
center_horizontal etc.

 android:orientation: This specifies the direction of arrangement and you will use
"horizontal" for a row, "vertical" for a column. The default is horizontal.

 android:weightSum: Sum up of child weight

06/03/2023
15 Different Layouts in Android-Relative Layout
 Relative layout is a type of layout used in Android app development that allows you to
position and align views relative to other views or the parent layout. It is useful when you
want to create a more flexible layout that can adapt to different screen sizes and
orientations.

06/03/2023
16 Different Layouts in Android-Relative Layout

 Attributes of relative layout:


 android:layout_alignParentStart / android:layout_alignParentLeft /
android:layout_alignParentEnd / android:layout_alignParentRight - These attributes are
used to align a view with the left or right edge of its parent layout.
 android:layout_alignParentTop / android:layout_alignParentBottom - These attributes are
used to align a view with the top or bottom edge of its parent layout.
 android:layout_toStartOf / android:layout_toLeftOf / android:layout_toEndOf /
android:layout_toRightOf - These attributes are used to position a view to the left or right
of another view.

06/03/2023
17 Different Layouts in Android-Relative Layout

 android:layout_above / android:layout_below - These attributes are used to position a view


above or below another view.

 android:layout_centerInParent - This attribute is used to center a view horizontally and


vertically within its parent layout.

 android:layout_centerHorizontal - This attribute is used to center a view horizontally


within its parent layout.

 android:layout_centerVertical - This attribute is used to center a view vertically within its


parent layout.
06/03/2023
18 Different Layouts in Android-Table Layout
 Android TableLayout is used to arrange groups of views into rows and columns. You will
use the <TableRow> element to build a row in the table. Each row has zero or more cells;
each cell can hold one View object.

06/03/2023
19 Different Layouts in Android-Table Layout
1 android:id
This is the ID which uniquely identifies the layout.

2 android:collapseColumns
This specifies the zero-based index of the columns to collapse. The column indices
must be separated by a comma: 1, 2, 5.

3 android:shrinkColumns
The zero-based index of the columns to shrink. The column indices must be separated
by a comma: 1, 2, 5.

4 android:stretchColumns
The zero-based index of the columns to stretch. The column indices must be
separated by a comma: 1, 2, 5
06/03/2023
20 Different Layouts in Android-Absolute Layout
 An Absolute Layout is used to specify exact locations (x/y coordinates) of its children.
Absolute layouts are less flexible and harder to maintain than other types of layouts without
absolute positioning.

06/03/2023
21 Different Layouts in Android-Absolute Layout

Sr.No Attribute & Description

1 android:id
This is the ID which uniquely identifies the layout.

2 android:layout_x
This specifies the x-coordinate of the view.

3 android:layout_y
This specifies the y-coordinate of the view.

06/03/2023
22 Different Layouts in Android-List View
 Android ListView is a view which groups several items and display them in vertical scrollable
list. The list items are automatically inserted to the list using an Adapter that pulls content
from a source such as an array or database.

 An adapter actually bridges between UI components and the data source that fill data into UI
Component. Adapter holds the data and send the data to adapter view, the view can takes the
data from adapter view and shows the data on different views like as spinner, list view, grid
view etc.

 The ListView and GridView are subclasses of AdapterView and they can be populated by


binding them to an Adapter, which retrieves data from an external source and creates a View
that represents each data entry.

06/03/2023
23 Different Layouts in Android-List View
Sr.No Attribute & Description
1 android:id
This is the ID which uniquely identifies the layout.
2 android:divider
This is drawable or color to draw between list items.
3 android:dividerHeight
This specifies height of the divider. This could be in px, dp, sp, in, or mm.
4 android:entries
Specifies the reference to an array resource that will populate the ListView.
5 android:footerDividersEnabled
When set to false, the ListView will not draw the divider before each footer
view. The default value is true.
6 android:headerDividersEnabled
When set to false, the ListView will not draw the divider after each header
view. The default value is true.

06/03/2023
24 List of UI Controls

 Button - This control is used to create a clickable button that performs an action when pressed.
 TextView - This control is used to display text on the screen, such as labels or instructions.
 EditText - This control is used to accept user input, such as text or numbers.
 ImageView - This control is used to display images on the screen.
 RadioButton - This control is used to create a group of mutually exclusive options that the user
can select from.
 CheckBox - This control is used to create a group of options that the user can select multiple
items from.

06/03/2023
25 Button
< Button android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me!"
android:onClick="onButtonClick" />

In Java file :
public void onButtonClick(View view) {
// Perform some action when the button is clicked
}

06/03/2023
26 TextView
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!" />

In Java file :

TextView myTextView = (TextView) findViewById(R.id.myTextView);


myTextView.setText("Hello, Android!");

06/03/2023
27 EditText
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name" />

In Java file :

EditText myEditText = (EditText) findViewById(R.id.myEditText);


String name = myEditText.getText().toString();

06/03/2023
28 CheckBox
<CheckBox
android:id="@+id/myCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I agree to the terms and conditions" />

In Java file :

CheckBox myCheckBox = (CheckBox) findViewById(R.id.myCheckBox);


if (myCheckBox.isChecked()) {
// Perform some action when the checkbox is checked
}
06/03/2023
29 RadioButton
<RadioGroup
android:id="@+id/myRadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />

06/03/2023
30 RadioButton
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2" />

</RadioGroup>
In Java File:
RadioGroup myRadioGroup = (RadioGroup) findViewById(R.id.myRadioGroup);
RadioButton radioButton1 = (RadioButton) findViewById(R.id.radioButton1);
RadioButton radioButton2 = (RadioButton) findViewById(R.id.radioButton2);

06/03/2023
31 ToggleButton

<ToggleButton
android:id="@+id/myToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="Off"
android:textOn="On" />
In Java File:
ToggleButton myToggleButton = (ToggleButton) findViewById(R.id.myToggleButton);

06/03/2023
32 ImageButton
<ImageButton
android:id="@+id/myImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_image" />
In Java File:
ImageButton myImageButton = (ImageButton) findViewById(R.id.myImageButton);
myImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Perform some action when the ImageButton is clicked
}
}); 06/03/2023
33 R.Java File
 The R.java file is an auto-generated class in Android that contains constants used to reference
resources such as layouts, strings, images, and other assets in an Android application.
 It's an important file in an Android project as it enables developers to reference resources in their
code using simple and readable names, rather than using resource IDs directly.
 Here are some of the reasons why the R.java file is important in Android:
1. Accessing resources: The R.java file provides a simple way to reference resources used in an Android
application.
2. Organizing resources: The R.java file organizes resources by type and name, making it easy for
developers to find and reference the resources they need.
3. Auto-generated: The R.java file is auto-generated by the Android build system, so developers don't have
to create it manually.
4. Error checking: The R.java file is checked by the Android build system for errors, such as missing
resources or duplicate resource IDs.

06/03/2023
34 Padding, Margin, Weightsum
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal“
android:padding="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:weightSum="3">

06/03/2023
35 Padding, Margin, Weightsum
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Left Text" />

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Right Text" />

</LinearLayout>
06/03/2023
36 Padding, Margin, Weightsum

 In this example, we have a horizontal LinearLayout that contains two TextView elements.
The LinearLayout has a padding of 16dp on all sides, and a margin of 8dp on the top and
bottom.
 Note that padding adds extra space inside the view, while margin adds extra space outside
the view. weightsum specifies the total weight of the child views, and is used to calculate
their relative sizes.
 The first TextView has a weight of 1, which means it will take up one-third of the available
horizontal space within the LinearLayout. The second TextView has a weight of 2, which
means it will take up two-thirds of the available horizontal space.

06/03/2023
GTU Questions

37

 Explain following properties of EditText: text, hint. (2 M)


 List any four layout types in android. (2 M)
 Draw an activity life cycle diagram.(2M)
 Explain password and editable attributes of TextView(2M)
 Define activity and intent.(2M)
 What is Toggle Button?(2M)
 Explain textOn and textOff property of ToggleButton. (2M)
 Give use of String.xml file in android.(2M)
 Write any four properties of EditText.(2M)
 List out Properties of Push Button and Toggle Button.(2M)
 Explain purpose of R.Java and Strings.xml File.(2M)

06/03/2023
GTU Questions

38

 Difference between TextView and EditText GUI Objects. (2 M)


 Define Intent. (2 M)
 Explain Linear Layout with its important properties.(3M)
 Explain Toggle Button with its important properties.(3M)
 Define Intent. How intent can be used to call built-in applications?(4M)
 Explain activity life cycle with diagram. (4M)
 Explain hardware based design criteria for android application. (3M)
 Explain Linear Layout with example.(3M)
 Explain Toggle Button with example.(3M)
 Explain Radio Button with example.(3M)
 Explain Padding and Margin with example. (4M)

06/03/2023
GTU Questions

39

 List Different Layout Types. Explain any one(3 M)


 Explain main parts of Android Project Framework. (3 M)
 Explain Android manifest file.(4M)
 Explain Listview in Detail.(3M)
 Explain checkbox and radio button widgets in android(3M)
 Explain Table and Relative layout of android. (3M)
 How to link Activities using Intent?(4M)
 Explain Android application priorities in short.(3M)

06/03/2023

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy