About .xml file in android

XML stands for eXtensible Markup Language. It is somehow similar to Html . It is designed to transport data and to be self-descriptive. The .xml file in android studio is basically used just to design the user interface.

In android’s xml vocabulary, we can design layouts ans the screen elements they contain, in the same way we create html webpages. To work in xml file in android we do not required to be expert in it , we just need to keep up with some basic elements.

Now in every xml contains a root element like view group and all elements are written in it, there can be multiple view groups in a single view group .

[sourcecode]</pre>
<pre><?xml version="1.0" encoding="utf-8"?>
<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="com.example.kaushal.myapplication.MainActivity">

<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:hint="Enter your name"
android:layout_gravity="center_horizontal"
android:id="@+id/name"
/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:hint="Enter your name"
android:layout_gravity="center_horizontal"
android:id="@+id/name2"
/>

</LinearLayout></pre>
<pre>[/sourcecode]

Now in above given code you can see there is a root element which is a liner layout and there
are two text view which are child to the root element.

Attributes

Every child or element supports different types of attributes according to their requirement (for example TextView support text size attribute).

ID :

Every view object required a unique identification so that it can be used to refer that element. It is defined as

[code]android:id="@+id/first_name"[/code]

 

 

About Layouts:

Basically there are three types of common layouts which are

  • Linear Layout
  • Relative Layout
  • Web view

Linear layout : It arranges elements in vertical or horizontal manner .To know more about Linear layout click here.

Relative layout : It arranges elements in relative to each other basically used to responsive designs and having a little more complex than linear layout.

Web View : Use to display web pages.

About kaushal97

Android Enthusiast

Leave a Reply

Your email address will not be published. Required fields are marked *