Himanshu Nautiyal
Gateway To Thoughts
2 min readNov 28, 2019

--

XML to Java code Conversion

XML is one of the easiest ways of creating attractive and pleasing UI . It is a well oriented and tagged language. Information coded in XML is easy to read and understand. It Contains machine-readable context information and Supports multilingual documents and Unicode.

Then Why java?

XML is a great language but sometimes it drops the performance of the app. This happens because most of the times we use repetitive words (like “android “ in app development) which increase compilation time. If the app needs to create the list of 1000 views with continuous updates it will be difficult for the users to smoothly access the list. So to solve this type of problems we use java instead of XML for creating the widgets or layouts

Let’s understand it with an example:

layout.xml

This is a simple XML code with A “FrameLayout” containing “LinearLayout” followed by a “TextView” and “ImageView”. Now let’s convert this code to java

Layout.java
Layout.kt

Initially we create a Parent layout( in our case it is “FrameLayout” ). Now set different properties of that layout. Similarly write the code for all widgets and layouts. Once this is done we have to simply add the widgets to the respective layout.

That’s it, now we are ready to use our view to improve the performance of the app

HAPPY CODING!!!

--

--