Experiment No 3 Aim: Theory:: Develop An Application That Uses GUI Components
Experiment No 3 Aim: Theory:: Develop An Application That Uses GUI Components
Experiment No 3
Theory:
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/ViewGroupobjects 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
1 Linear Layout
LinearLayout is a view group that aligns all children in a single direction, vertically or
horizontally.
2 Relative Layout
3 Table Layout
5 Frame Layout
The FrameLayout is a placeholder on screen that you can use to display a single view.
6 List View
7 Grid View
Buttons
Depending on whether you want a button with text, an icon, or both, you can create the button
in your layout in three ways:
With text, using the Button class:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text"
... />
With an icon, using the ImageButton class:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_icon"
... />
With text and an icon, using the Button class with the android:drawableLeft attribute:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text"
24 | P a g e
android:drawableLeft="@drawable/button_icon"
... />
1.Right-click the font folder and go to New > Font resource file. The New Resource File window
appears.
2.Enter the file name, and then click OK. The new font resource XML opens in the editor.
3.Enclose each font file, style, and weight attribute in the <font> element. The following XML
illustrates adding font-related attributes in the font resource XML:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/lobster_regular" />
<font
android:fontStyle="italic"
android:fontWeight="400"
android:font="@font/lobster_italic" />
</font-family>
AndroidUI Controls
There are number of UI controls provided by Android that allow you to build the graphical user
interface for your app.
1 TextView
25 | P a g e
2
EditText
26
EditText is a predefined subclass of TextView that includes rich editing |Page
capabilities.
3 AutoCompleteTextView
4 Button
5 ImageButton
6 CheckBox
An on/off switch that can be toggled by the user. You should use check box
when presenting users with a group of selectable options that are not mutually
exclusive.
7 ToggleButton
8 RadioButton
9 RadioGroup
10 ProgressBar
The ProgressBar view provides visual feedback about some ongoing tasks, such
as when you are performing a task in the background.
11 Spinner
A drop-down list that allows users to select one value from a set.
12 TimePicker
The TimePicker view enables users to select a time of the day, in either 24-hour
mode or AM/PM mode.
13 DatePicker
Result:
Conclusion: In this experiment we learn Develop an application that uses GUI components
27 | P a g e
Questionnaire
1) What is view?
View is a basic building block of UI (User Interface) in android. A view is a small rectangular box that
responds to user inputs. Eg: EditText, Button, CheckBox, etc. ViewGroup is an invisible container of
other views (child views) and other ViewGroup.
2) What is ViewGroup?
ViewGroup. A ViewGroup is a special view that can contain other views. The ViewGroup is the base
class for Layouts in android, like LinearLayout , RelativeLayout , FrameLayout etc. In other words,
ViewGroup is generally used to define the layout in which views(widgets) will be set/arranged/listed on
the android screen.
Linear Layout.
Relative Layout.
Constraint Layout.
Table Layout.
Frame Layout.
List View.
Grid View.
Absolute Layout.
LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally.
You can specify the layout direction with the android:orientation attribute. ... A LinearLayout respects
margins between children and the gravity (right, center, or left alignment) of each child.
In android GridView is a view group that display items in two dimensional scrolling grid (rows and
columns), the grid items are not necessarily predetermined but they are automatically inserted to the
layout using a ListAdapter. Users can then select any grid item by clicking on it
XML stands for Extensible Markup Language. XML is a markup language much like HTML used to
describe data. XML tags are not predefined in XML.
28 | P a g e
7) List all Android UI Controls.
Button. ...
ImageButton.
ToggleButton.
RadioButton..
RadioGroup. .
CheckBox.
Android radio button is a widget which can have more than one option to
choose from. The user can choose only one option at a time. Each option
here refers to a radio button and all the options for the topic are together
referred to as Radio Group. Hence, Radio Buttons are used inside a
RadioGroup.