MAD_Unit_No_3_Notes
MAD_Unit_No_3_Notes
• In the
below image, several important files/folders are marked:
Compiled by SAYYED SHABANA USMAN___ Page 1
1.
AndroidManifest.xml:
Every project in Android includes a manifest file, which is
AndroidManifest.xml, stored in the root directory of its project
hierarchy.The manifest file is an important part of our app
because it defines the
structure and metadata of our application, its components, and its
requirements.
This file includes nodes for each of the Activities, Services, Content
Providers and Broadcast Receiver that make the application and using
Intent Filters and Permissions, determines how they co-ordinate with
each other and other applications.
Below is the sample AndroidManifest.xml file:
<manifest xmlns:android="
http://schemas.android.com/apk/res/android"package="com.exam
ple.geeksforgeeks.geeksforgeeks"> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
2.
java:
The Java folder contains the Java source code files.
These files are used as a controller for controlled UI (Layout file).
It gets the data from the Layout file and after processing that data
output will be shown in the UI layout.
It works on the backend of an Android application.
3.
drawable:
The drawable folder contains resource type file (something that
can be drawn).
Drawables may take a variety of file like Bitmap (PNG, JPEG), Nine Patch,
Vector (XML), Shape, Layers, States, Levels, and Scale. 4.
layout:
A layout defines the visual structure for a user interface, such as the
UI for an Android application.
This folder stores Layout files that are written in XML language. 5.
mipmap:
The mipmap folder contains the Image Asset file that can be used in
Android Studio application.
You can generate the icon types like Launcher icons, Action bar
and tab icons, and Notification icons.
6.
colors.xml:
colors.xml file contains color resources of the Android application.
Different color values are identified by a unique name that can be used
in the Android application program.
Below is a sample colors.xml file:
<resources>
<color name="colorPrimary">#1294c8</color>
<color name="colorPrimaryDark">#1294c8</color>
</resources>
7.
strings.xml:
The strings.xml file contains string resources of the Android
application.
The different string value is identified by a unique namethat can be
used in the Android application program.
This file also stores string array by using XML language.
Below is a sample strings.xml file:
<resources>
Compiled by SAYYED SHABANA USMAN___ Page 3
<resources>
<string name="app_name">Workshop app</string> <string
name="date">Date:</string>
<string name="timings">Timings:</string>
</resources>
8.
styles.xml:
The styles.xml file contains resources of the theme stylein the Android
application.
This file is written in XML language.
Below is a sample styles.xml file:
<resources>
<!-- Base application theme. -->
<style name="AppTheme"
parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize
your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item> <item
name="colorPrimaryDark">@color/colorPrimaryDark</item> <item
name="colorAccent">@color/colorAccent</item> </style>
</resources>
9.
build.gradle(Module: app):
This defines the module-specific build configurations.
Here you can add dependencies what you need in your Android
View Groups are extensions of the View class that can contain
multiple child Views.
By extending the ViewGroup class, you can create compound
controls that are made up of interconnected child Views.
The ViewGroup class is also extended to provide the layout
managers, such as LinearLayout, that help you compose User
Interfaces.
ViewGroup is an invisible container of other views (child views)
and other ViewGroup.
LinearLayout, RelativeLayout, TableLayout, etc. are examples of
ViewGroup.
iii.
Activities:
Activities represent the window or screen being displayed to
the user. Activities are the Android equivalent of a Form.
To display a User Interface, you assign a View or layout to an
Activity. Android provides several common UI controls, widgets, and
layout managers.
3.3 Layouts (Linear Layout, Absolute Layout, Frame Layout, Table Layout,
Relative Layout)
It is a type of resource which gives definition on what is drawn on the screen or how
•
elements are placed on the device’s screen and stored as XML files in the
/res/layout resource directory for the application.
• It can also be a type of View class to organize other controls.
• There are many types of layout.
Some of which are listed below:
•
i. Linear Layout
ii. Absolute Layout
iii. Table Layout
iv. Frame Layout
v. Relative Layout
android:weightSum Defined in the layout, it sets the total weight sum of all the
sub-view
inside the layout.
activity_main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
activity_main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity">
<!-- Set Orientation as "horizontal" --> <!--sub view 1-->
<View
android:id="@+id/view_1"
android:background="@color/grey"
android:layout_width="wrap_content"
android:layout_margin="32dp"
android:layout_height="100dp" /> <!--sub view 2-->
<View
android:id="@+id/view_2"
android:background="@color/grey"
android:layout_width="wrap_content"
android:layout_margin="32dp"
android:layout_height="100dp" /> <!--sub view 3-->
<View
android:id="@+id/view_3"
android:background="@color/grey"
android:layout_width="wrap_content"
android:layout_margin="32dp"
android:layout_height="100dp" /> <!--sub view 4-->
<View
android:id="@+id/view_4"
android:background="@color/grey"
android:layout_width="wrap_content"
android:layout_margin="32dp"
android:layout_height="100dp" /> </LinearLayout>
Here’s a view of the design in the design layout: Compiled by SAYYED SHABANA
USMAN___ Page 8
3.3.3 FrameLayout:
Android FrameLayout is a ViewGroup subclass that is used to specify the position of
•
multiple views placed on top of each other to represent a single view
screen. • Generally, we can say FrameLayout simply blocks a particular area
on the screen to
Visit
https://developer.android.com/reference/android/widget/FrameLayout, for
more
•
details about FrameLayout.
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Steven Smith" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="AUS" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="820" />
</TableRow>
<TableRow android:background="#F0F7F7"
android:padding="5dp"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Ross Taylor" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="NZ" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="817" />
</TableRow>
</TableLayout>
3.3.5 RelativeLayout:
•
RelativeLayout in Android is a ViewGroup subclass, that allows users to
position child views relative to each other (e.g., view A to the right of
view B) or relative to the parent (e.g., aligned to the top of the parent).
Instead of using LinearLayout, we have to use RelativeLayout to design
the user
•
interface and keep our hierarchy flat because it improves the
performance of the application.
Unlike LinearLayout, which stacks the views in a particular direction,
RelativeLayout
•
allows more flexibility and dynamic UIs while maintaining a flat view
hierarchy. Compiled by SAYYED SHABANA USMAN___ Page 17
•
Important Attributes for Positioning Views in the RelativeLayout:
As we know, we need to define the position of child views or ViewGroups
relative to each other element or relative to the parent. By default position is
top-left, if someone forgets to specify the position of child views.
layout_alignParentTo
XML attributes p
layout_alignParentLef
t Description
layout_alignParentRig Set “true” to match the left edge of
ht view to the left edge of parent.
Set “true” to match the right edge of
view to the right edge of the parent.
the view to the top
edge of the parent.
layout_centerInParent
layout_centerHorizont
al
layout_centerVertical
It accepts another sibling view ID and
layout_toLeftOf Align the view to
the end of the specified view ID.
layout_toRightOf When it is set to “true”, the view will be
aligned to the
layout_toStartOf center of parent.
layout_toEndOf
layout_above
layout_below
Visit https://developer.android.com/reference/android/widget/RelativeLayout,
for more
•
details about RelativeLayout.
Compiled by SAYYED SHABANA USMAN___ Page 21