Basic XML for Android Devs

Jan 14, 2021Ā·

2 min read

Basic XML for Android Devs

Hey Android Devs šŸ‘‹, here I am going to explain the basic syntax of XML as a Android Developer to know.

Letā€™s startā€¦.

Introduction:

XML stands for eXtensible Markup Languageā€¦ What is this mean? It is a markup (Designing or skeleton) language that define the data structureā€¦

XML is also used in data transfer in APIs.

Tags:

In XML, there is two types of tags.

  1. Normal tag
  2. Self closing tag

Normal tag:

<MyTag> ā€¦childrenā€¦ </MyTag>

It has both opening tag and closing tag

Self closing tag:

<MySelfTag />

Since the name suggests it contains no closing tagā€¦ It is useful when there is no children.

Attributes:

Tags can have multiple attributes..

Attributes consists of two components:

  • Attribute key
  • Attribute value (it must be wrapped in double quotes)
  • Namespace (optional in xml, but required in android layouts)

Note: Each key must be unique

These are the basic things in XML.. Now letā€™s dive in to The Android World.

In Android, each tag represents a View or ViewGroup class.
If the attribute is provided by Android, it must have namespace android: .
Each Tag must have two specific attributes layout_width and layout_height .

Note: Value of layout_width and layout_height may be match_parent | wrap_content | values in units .

If the Tag is a View, write that tag in self closing tag, else in normal tag

Refer this Video:

Thank you reading my postā€¦ See you in next storyā€¦