Introducing to XML

Phúc Ngô Hồng
Jul 10, 2017 · 2 min read

XML stands for eXtensible Markup Language and was designed to be a software and hardware independent tool used to transport and store data, with focus on what data is. XML is mostly used for user interface (UI) layouts in Android. Wonder why we need to use XML? XML is easy to parse and manipulate programmatically with a really simple tree-structure.

Tree-structure of a Layout XML

There are several types of XML file that we should focus on:

Layout XML: we use it to define the actual UI of our application. It’s capable of holding many tools and elements like TextView, Button or even other layouts

A Layout XML displays “Hello World”

Manifest XML: it is used to define all the components of your application. It includes the names of your packages, your classes(Activities), services, receivers and the permissions that your application needs. We’ll talk about this XML later.

This XML is kinda complex and you will be explained later

String XML: we use it to hard-coded, long string with a single substitute string. For instance, “Hello world” can be replaced by “Hw” if you define it in this XML.

Hello World is now replace by Hello

Style XML: This XML is used to different styles and looks for the UI, like color for a specific element of your application.

Style XML sample

Drawable XML: it is used to provide abundant of graphics for your application.

At first, we will only concentrate on one type of XML file, Layout XML, as I assume this is the most fundamental XML of our applications.

Now you can try to re-code the sample XML layout below (copy would not work) or copy my code from Github to this awesome XML visualizer from Udacity:

<LinearLayout android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<TextView
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Hello world”
/>
</LinearLayout>

Awesome, you just created your first layout :D .

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade