Mad Unit 3
Mad Unit 3
Mad Unit 3
layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</LinearLayout>
mipmap:
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.
colors.xml:
<resources>
<string name="app_name">MM Polytechnic</string>
</resources>
styles.xml:
The styles.xml file contains resources of the theme style in 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>
</style>
</resources>
build.gradle(Module: app):
There are many types of layout. Some of which are listed below −
• Linear Layout
• Absolute Layout
• Table Layout
• Frame Layout
• Relative Layout
LINEAR LAYOUT
Linear layout is further divided into horizontal and vertical layout.
It means it can arrange views in a single column or in a single
row. Here is the code of linear layout(vertical) that includes a
text view.
A layout that organizes its children into a single horizontal or
vertical row. It creates a scrollbar if the length of the window
exceeds the length of the screen
Linear Layout
<?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” >
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello” />
</LinearLayout>
ABSOLUTELAYOUT
<TableLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_height=”fill_parent” android:layout_width=”fill_parent” >
<TableRow>
<TextView android:text=”User Name:” android:width =”120dp” />
<EditText android:id=”@+id/txtUserName” android:width=”200dp” />
</TableRow> </TableLayout>
RELATIVELAYOUT
RelativeLayout enforces to display elements in relations to each other.
You can specify that, for instance, one UI element can be said to be
placed on the left of another element, or on the bottom of another etc.
Each UI element can also be positioned according to the layout’s
borders (e.g. aligned to the right)
RELATIVELAYOUT
It can be declared like this.
<RelativeLayout
android:id=”@+id/RLayout”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
xmlns:android=”http://schemas.android.com/apk/res/android” >
<TextView
android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="110dp"
android:text="UserName:"
android:textColor="#000000"
android:textSize="20sp" />
<TextView
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/userName"
android:text="Password:"
android:textColor="#000000"
android:textSize="20sp" />
FRAMELAYOUT
android:layout_height="wrap_content"
The FrameLayout is a
android:layout_centerHorizontal="true"
placeholder on screen that you android:layout_marginTop="80dp"
can use to display a single view. android:hint="Enter your email"
It can be declared like this. android:padding="10dp" />
<?xml version=”1.0” encoding=”utf-8”?> <EditText
<FrameLayout android:id="@+id/editText2"
xmlns:android=http://schemas.android.com/apk/res/android android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="match_parent" android:layout_centerHorizontal="true"
android:orientation="vertical“ > android:layout_marginTop="150dp"
<TextView android:hint="Enter password"
android:id="@+id/txtvw1" android:padding="10dp" />
android:layout_width="wrap_content" <Button
android:layout_height="wrap_content" android:id="@+id/btn1"
android:layout_marginLeft="100dp" android:layout_width="wrap_content"
android:layout_marginTop="10dp" android:layout_height="wrap_content"
android:padding="10dp“ android:layout_marginLeft="110dp"
android:text="Login Details" /> android:layout_marginTop="240dp"
<EditText android:text="Submit" />
android:id="@+id/editText1" </FrameLayout>
android:layout_width="match_parent"
OTHER ATTRIBUTES THAT ARE COMMON IN ALL VIEWS AND VIEWGROUPS
Sr.No View & description
1 layout_width
Specifies the width of the View or ViewGroup
2 layout_height
Specifies the height of the View or ViewGroup
3 layout_marginTop
Specifies extra space on the top side of the View or ViewGroup
4 layout_marginBottom
Specifies extra space on the bottom side of the View or ViewGroup
5 layout_marginLeft
Specifies extra space on the left side of the View or ViewGroup
6 layout_marginRight
Specifies extra space on the right side of the View or ViewGroup
7 layout_gravity
Specifies how child Views are positioned
8 layout_weight
Specifies how much of the extra space in the layout should be allocated to
the View