0% found this document useful (0 votes)
67 views30 pages

Chapter 1 Mad

The document discusses Android, an operating system for mobile devices. It covers what Android is, its history and development, architecture, tools needed for development including operating systems, Java JDK and Android SDK, and installation and configuration of the Android SDK.
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)
67 views30 pages

Chapter 1 Mad

The document discusses Android, an operating system for mobile devices. It covers what Android is, its history and development, architecture, tools needed for development including operating systems, Java JDK and Android SDK, and installation and configuration of the Android SDK.
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/ 30

Chapter No: 1

Android and its Tools

1.1 Introduction to Android

Android is a complete set of software for mobile devices such as tablet computers, notebooks,
smartphones, electronic book readers, set-top boxes etc.
It contains a Linux-based Operating System, middleware and key mobile applications.
It can be thought of as a mobile operating system. But it is not limited to mobile only. It is
currently used in various devices such as mobiles, tablets, televisions etc.

What is Android?

Android is a software package and linux based operating system for mobile devices such as
tablet computers and smartphones.
It is developed by Google and later the OHA (Open Handset Alliance). Java language is
mainly used to write the android code even though other languages can be used.
The goal of android project is to create a successful real-world product that improves the
mobile experience for end users.
There are many code names of android such as Lollipop, Kitkat, Jelly Bean, Ice cream
Sandwich, Froyo, Ecliar, Donut etc

Fig Android Logo

What is “Open Handset Alliance?”

It was established on 5th November, 2007, led by Google.


It is committed to advance open standards, provide services and deploy handsets using the
Android Plateform.
The OHA is a business alliance that consists of 84 companies such as google, samsung,
AKM, synaptics, KDDI,Teleca, Ebay, Intel etc. for developing open standard platform for
mobile devices.
The members of OHA include handset manufactures, chip makers, commercialization
companies, software companies and mobile operators.

Fig. Open Handset Alliance

Android Ecosystem
If we want to learn about Android and develop Android Applications, it is very important for
us to understand the entire ecosystem of Android and the stakeholders of this ecosystem.
The stakeholders are the consumers that own Android devices. But there are others as well
1.Google: it develops Android.
2. OEMs (Original Equipment Manufacturers):
They Manufacture the hardware, and as well the custom application components.
3. Application Development Companies:
They are the major contributors to the ecosystem and employ Android developers, and also
contract out the product development to services companies.
4. Freelance Android developers:
Developers have the skill-set to contribute to the ecosystem for Android development, they are
who create their own application, and publish them on Google play store.
Freelancers can also generate money by developing applications for product companies.

1.2 Need of Android

Why Android?
There are some points:
1. Browser:
The Android browser is one of the best browsers on the mobile market.
It generally loads pages faster than Safari or any other browser, has flash support and simply
does everything a browser should do.
E.g. iPhone has safari browser it is stable, has no flash support, so you cannot watch
YouTube videos or any related contents, it is not flexible.
2. Desktop:
The Android phone adds widgets to the desktop. The purpose for the widget
e.g.
The Facebook widget allows you to update your Facebook desktop.
The people widget allows you to make possible different actions for different contacts right
from your desktop.
The message widget allows you to immediately see your email from the desktop.
3. Connectivity: On one page/desktop you could be able to have four connecting device tool
button.
Turn on/off Bluetooth.
Turn on/off WiFi.
Turn on/off mobile network.
Turn on/off GPS.
These buttons let you switch on/off instantly which will help you to conserve battery life.
4. Multi-Notification: Android Phone have multi-notification system. With android the app
have access to the notification system and call all report.
5. Endless Personalization: The Android cell phone allows client to configuration their mobile
to look and behave exactly like they want.
6. Market: Android has an android market. The Android apps are free and work as well.
7. Google Integration: The Android has inbuilt google support. E.g. Google map, Gmail etc.
8. Open Source: The code of android OS as well as the apps is available.
9. Open to Carrier: If you know java then you are open to Android world.
10. Future: The future mobile phones are basically going to be smart phones.

Features of Android

The important features of android are given below:


1) It is open-source.
2) Anyone can customize the Android Platform.
3) There are a lot of mobile applications that can be chosen by the consumer.
4) It provides many interesting features like weather details, opening screen, live RSS (Really
Simple Syndication) feeds etc.
5) It provides support for messaging services (SMS and MMS), web browser, storage (SQLite),
connectivity (GSM, CDMA, Blue Tooth, Wi-Fi etc.), media, handset layout etc.

History of Android
History and versions of android are interesting to know. The code names of android ranges
from A to J currently, such as Aestro, Blender, Cupcake, Donut, Eclair, Froyo, Gingerbread,
Honeycomb, Ice Cream Sandwitch, Jelly Bean, KitKat and Lollipop. Let's understand the
android history in a sequence.
1) Initially, Andy Rubin founded Android Incorporation in Palo Alto, California, United
States in October, 2003.
2) In 17th August 2005, Google acquired android Incorporation. Since then, it is in the
subsidiary of Google Incorporation.
3) The key employees of Android Incorporation are Andy Rubin, Rich Miner, Chris White
and Nick Sears.
4) Originally intended for camera but shifted to smart phones later because of low market for
camera only.
5) Android is the nick name of Andy Rubin given by coworkers because of his love to robots.
6) In 2007, Google announces the development of android OS.
7) In 2008, HTC launched the first android mobile.

Android Versions, Codename and API

Version Code name API Level

1.5 Cupcake 3

1.6 Donut 4

2.1 Eclair 7

2.2 Froyo 8

2.3 Gingerbread 9 and 10

3.1 and 3.3 Honeycomb 12 and 13

4.0 Ice Cream Sandwitch 15

4.1, 4.2 and 4.3 Jelly Bean 16, 17 and 18

4.4 KitKat 19

5.0 Lollipop 21

6.0 Marshmallow 23

7.0 Nougat 24-25

8.0 Oreo 26-27


1.4 Android Architecture.

Android architecture or Android software stack is categorized into five parts:


Linux kernel
Native libraries (middleware),
Android Runtime
Application Framework
Applications

1. Linux kernel
It is the heart of android architecture that exists at the root of android architecture. Linux
kernel is responsible for device drivers, power management, memory management, device
management and resource access
2) Native Libraries
On the top of linux kernel, there are Native libraries such as WebKit, OpenGL, FreeType,
SQLite, Media, C runtime library (libc) etc.
The WebKit library is responsible for browser support, SQLite is for database, FreeType for
font support, Media for playing and recording audio and video formats.
3. Android Runtime
In android runtime, there are core libraries and DVM (Dalvik Virtual Machine) which is
responsible to run android application. DVM is like JVM but it is optimized for mobile devices.
It consumes less memory and provides fast performance.
4) Android Framework
On the top of Native libraries and android runtime, there is android framework. Android
framework includes Android API's such as UI (User Interface), telephony, resources, locations,
Content Providers (data) and package managers. It provides a lot of classes and interfaces for
android application development.
5) Applications
On the top of android framework, there are applications. All applications such as home, contact,
settings, games, browsers are using android framework that uses android runtime and libraries.
Android runtime and native libraries are using linux kernal
Chapter No: 2

Installation and configuration of android


2.1 Operating system, java JDK, Android SDK.
2.1.1 Operating System.
To develop an android program the necessary supporting operating system used in a
computer can be as follows.
Windows XP(32 bit), vista (32 or 64 bit), or windows 7 ,8,10 (32 or 64bit)
Mac OS X(Intel) 10.5.8 (x86 only)
Linux (i386: tested in lucid lynx, Ubuntu linux)
GNC C Library 2.7 or later is required.
On Ubuntu Linux , version 8.04 or later is required.
64 bit distributions should be capable of running 32 bit applications
2.1.2 Java JDK
As android programs are developed in the java programming language we have to install
java development kit (jdk) in computer which is a free software where the jdk includes the
java SE Runtime (JRE).
2.1.3 Android SDK

 The android SDK (Software development kit) is the most important software of
android which is installed.
 The android SDK provides to test android applications, the API libraries, an
emulator, documentation, sample code, developer tools and tutorials which help you
to build, test, and debug apps for android.
 Android SDK can be downloaded from http://developer.android.com/sdk/index.html
using android SDK manager which is free.
 We find the android SDK in a zip file and have to unzip its contents into a folder.
 We can also create android virtual devices (AVD) via the android SDK, which run in
the emulator.

Android SDK is made up of two main parts.

 Tools
 Packages

When you first install the SDK all you obtain are the base tools.
These are executables and supporting files that help you develop applications.
The packages are the records specific to a particular version of android (called a platform) or
a particular add- on to a platform.

Android SDK features


1. No licensing, distribution, or development fees.
2. Wi-fi hardware access.
3. GSM, and 3G networks for telephony or data transfer, allow you to make or receive calls
or SMS messages, otherwise to send and retrieve data across mobile networks.
4. Comprehensive APIs designed for location based services such as GPS.
5. Full multimedia hardware control together with playback and recording using the camera
and microphone.
6. Shared data stores.
7. Media libraries designed for playing and recording a variety of audio/video or still image
formats.
Platform used:
To develop android application we use the Eclipse, intelliJ, and AIDE different integrated
development environments (IDEs) which supports multiple languages such as Java, C, C++,
COBOL, Python etc.
2.2 Android development Tools (ADT)

 Android development tools is a plugin for the eclipse IDE which provides a suitable
environment to develop an android application where creation, compilation and
debugging are possible.
 ADT can able to set up new android projects, create an application UI, insert packages
based on the android framework API, Debug your applications using the android SDK
tools and export signed or unsigned .apk files in order to distribute in the application.

The works of ADT in Eclipse are,

 Also ADT provides custom XML editors and debug output pane from which we get
the unbelievable enhance during develop the android applications.

Android developer tools bundle provides,

 Eclipse + ADT plugin.


 Android SDK tools.
 Android platform tools.
 The most recent android platform.
 The newest android system image for the emulator.

Android Virtual Devices (AVDS)

 An android virtual device is an emulator configurations that enables to model an


actual device by calling hardware and software options to be emulated by the android
emulator.
 Use the AVD manager to create an AVD. Launch it from android studio by clicking
windows AVD manager.
 An android virtual devices is used for testing the android application.

An AVD consists of:


A hardware profile:-

 Defines the hardware features of the virtual device. For example, you can describe
whether the device has camera, whether it uses a physical keyboard or a dialing pad,
how much memory it have and so on.

A mapping to a system image:

 You can define what version of the android platform will run on the virtual machine.
 You will be able to choose a version of the standard android platform or the system
image packaged with an sdk add on.
 You can specify the emulator skin you want to use with the AVD which lets you to
control the screen dimensions, look, and so on.
 A dedicated storage area on your development machine:
 The devices user data (installed, applications, settings, and so on) and emulated SD
card are stored in this area.

 We can generate as many AVDS as we want to analysis the applications with some
different configurations.
 This testing is essential to confirm the performance of the applications when it is run
on different devices with changing capabilities.

Emulators

 Android Emulator is used to run, debug and test the android application. If you don't
have the real device, it can be the best way to run, debug and test the application.
It uses an open source processor emulator technology called QEMU.
 The emulator tool enables you to start the emulator from the command line. You
need to write: emulator -avd <AVD NAME>
 In case of Eclipse IDE, you can create AVD by Window menu > AVD Manager >
New.
 In the given image, you can see the android emulator, it displays the output of the
hello android example.

 The android SDK comes with a virtual mobile device emulator that runs on your
computer.
 The emulator enables us trial product, to develop and test android applications
without using a physical device.
 The android emulator mimics all of the hardware and software features of typical
mobile devices, except that it cannot place actual phone calls.
 It provides a selection of navigation and control keys, which you can press using your
mouse or keyboard to generate events for our application.
 It provides a screen in which our application is displayed, together with any other
active android applications.
 The android emulator supports many hardware features likely to be found on mobile
devices including: An ARM v5 CPU and the corresponding memory management
unit(MMU)
 A 16 bit LCD display
 one or more keyboards
 A sound chip among output and input capabilities.
 Flash memory partitions.
 A GSM modem including a simulated SIM card.
 A camera using a webcam connected to our development computer.
 Sensors like an accelerometer, using records from a USB connected Android device.

Dalvik Virtual Machine (DVM)

 As we know the modern JVM is high performance and provides excellent memory
management. But it needs to be optimized for low-powered handheld devices as well.
 The Dalvik Virtual Machine (DVM) is an android virtual machine optimized for
mobile devices. It optimizes the virtual machine for memory, battery life and
performance.
 Dalvik is a name of a town in Iceland. The Dalvik VM was written by Dan Bornstein.
 The Dex compiler converts the class files into the .dex file that run on the Dalvik
VM. Multiple class files are converted into one dex file.

Let's see the compiling and packaging process from the source file:
 The javac tool compiles the java source file into the class file.
 The dx tool takes all the class files of your application and generates a single .dex file.
It is a platform-specific tool.
 The Android Assets Packaging Tool (aapt) handles the packaging process.

Difference between JVM and DVM

JVM DVM
1 JVM supports multiple operating system. DVM supports only android operating
system.
2 It compiles java bytecode It compiles Dalvik bytecode
3 It forms separate classes in separate It forms multiple class in one .dex byte code
.class byte code file. file.
4 It runs on more memory It runs on less memory.
5 JVM is based on stack based virtual DVM is based on Register based virtual
machine architecture. machine architecture.
6 The executable format of JVM is The executable format of DVM is APK(only
JAR(one or more .class files.) one .dex files.)
7 It has different constant pools It has common constant pool.
8 JVM runs .class byte code directly the .class byte codes are optimized to .dex
format before executing in DVM

How to make android apps

 In this page, you will know how to create the simple hello android application. We
are creating the simple example of android using the Eclipse IDE. For creating the
simple example:
 Create the new android project
 Write the message (optional)
 Run the android application

Hello Android Example

 You need to follow the 3 steps mentioned above for creating the Hello android
application.

1) Create the New Android project


For creating the new android studio project:
1) Select Start a new Android Studio project

2) Provide the following information: Application name, Company domain, Project


location and Package name of application and click next.
3) Select the API level of application and click next.

4) Select the Activity type (Empty Activity).


5) Provide the Activity Name and click finish.

 After finishing the Activity configuration, Android Studio auto generates the activity
class and other required configuration files.
 Now an android project has been created. You can explore the android project and
see the simple program, it looks like this:
Chapter No: 3
UI COMPONENTS AND LAYOUTS
UI Layouts

 The basic building block for user interface is a View object which is created from the
View class and occupies a rectangular area on the screen and is responsible for
drawing and event handling.
 View is the base class for widgets, which are used to create interactive UI components
like buttons, text fields, etc.
 The ViewGroup is a subclass of View and provides invisible container that hold other
Views or other ViewGroups and define their layout properties.
 At third level we have different layouts which are subclasses of ViewGroup class and
a typical layout defines the visual structure for an Android user interface and can be
created either at run time using View/ViewGroup objects or you can declare your
layout using simple XML file main_layout.xml which is located in the res/layout
folder of your project.

Android Layout Types


There are number of Layouts provided by Android which you will use in almost all the
Android applications to provide different view, look and feel.

1. Linear Layout

 LinearLayout is a view group that aligns all children in a single direction, vertically or
horizontally.
 Android LinearLayout is a view group that aligns all children in either vertically or
horizontally.
We are having two options
1. fill_parent
2. wrap_content
1. fill_parent_width

 change the “layout_width” to “fill_parent” now the buttons width will fill in the
remaining spaces, just as big as its parent “linearlayout”, but buttons height is still
enough to enclose its content only.

2. wrap_content:

 A button component set “wrap_content” on both width and height attribute. it tell
android to display the button big enough to enclose its content.

LinearLayout Attributes
Following are the important attributes specific to LinearLayout −
1. android:id
This is the ID which uniquely identifies the layout.
2. android:baselineAligned
This must be a boolean value, either "true" or "false" and prevents the layout from aligning its
children's baselines.
3. android:baselineAlignedChildIndex
When a linear layout is part of another layout that is baseline aligned, it can specify which of
its children to baseline align.
4. android:divider
This is drawable to use as a vertical divider between buttons. You use a color value, in the
form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".
5. 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.
6. android:orientation
This specifies the direction of arrangement and you will use "horizontal" for a row, "vertical"
for a column. The default is horizontal.
7. android:weightSum
Sum up of child weight
Example

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button android:id="@+id/btnStartService"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:text="start_service"/>
<Button android:id="@+id/btnPauseService"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:text="pause_service"/>

<Button android:id="@+id/btnStopService"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:text="stop_service"/>

</LinearLayout>
2. Relative Layout

 RelativeLayout is a view group that displays child views in relative positions.


 Android RelativeLayout enables you to specify how child views are positioned
relative to each other.
 The position of each view can be specified as relative to sibling elements or relative to
the parent.

RelativeLayout Attributes
Following are the important attributes specific to RelativeLayout −
1. android:id
This is the ID which uniquely identifies the layout.
2. 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.
3. android:ignoreGravity
This indicates what view should not be affected by gravity.
Using RelativeLayout, you can align two elements by right border, or make one below
another, centered in the screen, centered left, and so on. By default, all child views are drawn
at the top-left of the layout, so you must define the position of each view using the various
layout properties available from RelativeLayout.LayoutParams and few of the important
attributes are given below −
1. android:layout_above
Positions the bottom edge of this view above the given anchor view ID and must be a
reference to another resource, in the form "@[+][package:]type:name"
2. android:layout_alignBottom
Makes the bottom edge of this view match the bottom edge of the given anchor view ID and
must be a reference to another resource, in the form "@[+][package:]type:name".
3. android:layout_alignLeft
Makes the left edge of this view match the left edge of the given anchor view ID and must be
a reference to another resource, in the form "@[+][package:]type:name".
4. android:layout_alignParentBottom
If true, makes the bottom edge of this view match the bottom edge of the parent. Must be a
boolean value, either "true" or "false".
5. android:layout_alignParentEnd
If true, makes the end edge of this view match the end edge of the parent. Must be a boolean
value, either "true" or "false"
6. android:layout_alignParentLeft
If true, makes the left edge of this view match the left edge of the parent. Must be a boolean
value, either "true" or "false".
7. android:layout_alignParentRight
If true, makes the right edge of this view match the right edge of the parent. Must be a
boolean value, either "true" or "false".
8. android:layout_alignParentStart
If true, makes the start edge of this view match the start edge of the parent. Must be a boolean
value, either "true" or "false".
9. android:layout_alignParentTop
If true, makes the top edge of this view match the top edge of the parent. Must be a boolean
value, either "true" or "false".
10. android:layout_alignRight
Makes the right edge of this view match the right edge of the given anchor view ID and must
be a reference to another resource, in the form "@[+][package:]type:name".
11. android:layout_alignStart
Makes the start edge of this view match the start edge of the given anchor view ID and must
be a reference to another resource, in the form "@[+][package:]type:name".
12.android:layout_alignTop
Makes the top edge of this view match the top edge of the given anchor view ID and must be
a reference to another resource, in the form "@[+][package:]type:name".
13. android:layout_below
Positions the top edge of this view below the given anchor view ID and must be a reference
to another resource, in the form "@[+][package:]type:name".
14. android:layout_centerHorizontal
If true, centers this child horizontally within its parent. Must be a boolean value, either "true"
or "false".
15. android:layout_centerInParent
If true, centers this child horizontally and vertically within its parent. Must be a boolean
value, either "true" or "false".
16. android:layout_centerVertical
If true, centers this child vertically within its parent. Must be a boolean value, either "true" or
"false".
17.android:layout_toEndOf
Positions the start edge of this view to the end of the given anchor view ID and must be a
reference to another resource, in the form "@[+][package:]type:name".
18.android:layout_toLeftOf
Positions the right edge of this view to the left of the given anchor view ID and must be a
reference to another resource, in the form "@[+][package:]type:name".
19. android:layout_toRightOf
Positions the left edge of this view to the right of the given anchor view ID and must be a
reference to another resource, in the form "@[+][package:]type:name".
20. android:layout_toStartOf
Positions the end edge of this view to the start of the given anchor view ID and must be a
reference to another resource, in the form "@[+][package:]type:name".

Following is the content of the modified main activity file


src/com.example.demo/MainActivity.java. This file can include each of the fundamental lifecycle
methods.

package com.example.demo;

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

public class MainActivity extends Activity {


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

}
Following will be the content of res/layout/activity_main.xml file –

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >

<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/reminder" />

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentStart="true"
android:layout_below="@+id/name">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2" />

</LinearLayout>

</RelativeLayout>

o/p
3. Table Layout

 TableLayout is a view that groups views into rows and columns.


 Android TableLayout going to be arranged 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.

 TableLayout containers do not display border lines for their rows, columns, or cells.

TableLayout Attributes
Following are the important attributes specific to TableLayout −
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.
example
Following is the content of the modified main activity file
src/com.example.demo/MainActivity.java. This file can include each of the fundamental
lifecycle methods.
package com.example.demo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Following will be the content of res/layout/activity_main.xml file −

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textClock"
android:layout_column="2" />
</TableRow>
<TableRow>
<TextView
android:text="First Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
<EditText
android:width="200px"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>

<TableRow>
<TextView
android:text="Last Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
<EditText
android:width="100px"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:layout_column="2" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/button"
android:layout_column="2" />
</TableRow>
</TableLayout>
4. Frame Layout

 The FrameLayout is a placeholder on screen that you can use to display a single view.
 Frame Layout is designed to block out an area on the screen to display a single item.
 Generally, FrameLayout should be used to hold a single child view, because it can be
difficult to organize child views in a way that's scalable to different screen sizes
without the children overlapping each other.
 You can, however, add multiple children to a FrameLayout and control their position
within the FrameLayout by assigning gravity to each child, using the
android:layout_gravity attribute

FrameLayout Attributes
Following are the important attributes specific to FrameLayout −
1. android:id
This is the ID which uniquely identifies the layout.
2. android:foreground
This defines the drawable to draw over the content and possible values may be a color value,
in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".
3. android:foregroundGravity
Defines the gravity to apply to the foreground drawable. The gravity defaults to fill. Possible
values are top, bottom, left, right, center, center_vertical, center_horizontal etc.
4. android:measureAllChildren
Determines whether to measure all children or just those in the VISIBLE or INVISIBLE state
when measuring. Defaults to false.
Following is the content of the modified main activity file
src/com.example.demo/MainActivity.java. This file can include each of the fundamental
lifecycle methods.
package com.example.demo;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Following will be the content of res/layout/activity_main.xml file −
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:src="@drawable/ic_launcher"
android:scaleType="fitCenter"
android:layout_height="250px"
android:layout_width="250px"/>
<TextView
android:text="Frame Demo"
android:textSize="30px"
android:textStyle="bold"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center"/>
</FrameLayout>

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