Professional Documents
Culture Documents
Mobile Application Development Chap-2. Designing The User Interface
Mobile Application Development Chap-2. Designing The User Interface
Views
View is the basic building block of UI(User Interface) in android. View refers to
the android.view.View class, which is the super class for all the GUI components
like TextView, ImageView, Button etc.
View class extends Object class and
implements Drawable.Callback, KeyEvent.Callback and AccessibilityEventSource.
View can be considered as a rectangle on the screen that shows some type of content. It can be
an image, a piece of text, a button or anything that an android application can display. The
rectangle here is actually invisible, but every view occupies a rectangle shape.
A View is also known as Widget in Android. Any visual(that we can see on screen) and
interactive(with which user can interact with) is called a Widget.
Every view in XML has the following format:
<ViewName
Attribute1=Value1
Attribute2=Value2
Attribute3=Value3
AttributeN=ValueN
/>
It always start with an angle bracket, followed by the View name. We will introduce you
to various types of Views very soon.
Then we write attributes that will define how that view will look on the screen of the
application along with a value for the attribute. Each view has its own attributes which we
will discuss in the next few tutorials which will cover various typs of views.
Most commonly used Android View
Here we have some of the most commonly used android View classes:
TextView
EditText
Button
ImageView
ImageButton
CheckBox
RadioButton
ListView
GridView
DatePicker
Spinner, etc.
View Groups
5. ViewPager: - Used for managing multiple views while only displaying one at a time,
the ViewPager class accepts an Adapter and allows users to swipe left and right in order to see
all available View items.
Introducing layouts: - Layout is what defines the look of your app. You can
use the drag and drop GUI objects and properties section of Android Studio to build your
layouts to an extent but although convenient you will soon find out that you will need to
tweak the XML code of your layout quite often to actually make your app look the way you
want it to look. If you remember from previous post where we build the “Hello World” app,
Android actually creates a default layout file for us (activity_main.xml) when we create a
new project. You can find it inside the layout folder of your app structure as shown below.
Remember you can name this file anything you want when creating a new project.
Creating new views: - Use the simple “Hello World” Program.
(Present in Android).
The options menu is the primary collection of menu items for an activity. It's where you
should place actions that have a global impact on the app, such as "Search," "Compose
email," and "Settings."
A context menu is a floating menu that appears when the user performs a long-click on
an element. It provides actions that affect the selected content or context frame.
The contextual action mode displays action items that affect the selected content in a
bar at the top of the screen and allows the user to select multiple items.
3. Popup menu
A popup menu displays a list of items in a vertical list that's anchored to the view that
invoked the menu. It's good for providing an overflow of actions that relate to specific
content or to provide options for a second part of a command. Actions in a popup menu
should not directly affect the corresponding content—that's what contextual actions are
for. Rather, the popup menu is for extended actions that relate to regions of content in
your activity.
To define the menu, create an XML file inside your project's res/menu/ directory and
build the menu with the following elements:
<menu>
Defines a Menu, which is a container for menu items. A <menu> element must be the
root node for the file and can hold one or more <item> and <group> elements.
<item>
Creates a MenuItem, which represents a single item in a menu. This element may
contain a nested <menu> element in order to create a submenu.
<group>