Why is non-XML XML used for user interface in Android progrmming?

Why can't HTML be used to create an interface in Android programming?

+4
source share
5 answers

XML allows us to create custom tags. Consider that we created a custom view, we can refer to them from the XML itself. Thus, the idea of ​​a UI branch from logic remains unchanged.

+5
source

HTML is a standard for displaying web pages. Android XML files are custom configuration files that should be parsed by the dalvik virtual machine. Two separate worlds. Here are some good reasons not to use HTML to define your configuration.

  • HTML is not formed. Parsing is a pain. No circuit check.
  • How will you style the elements? CSS?
  • Its quite difficult to get CSS to work across multiple browsers.
  • How do you enter custom elements in your HTML configuration?

I could continue. It just doesn't make sense to customize your own user interface using HTML.

+1
source

I think xml is selected because xml tags are defined in android according to the classes of the user interface, and attributes are defined according to the member variables of the class in the user interface structure. This mapping is not possible for html.

0
source

I think there are several reasons for this:

  • If you have Layout and Source code separately, you can separate your application logic. Thus, many XML files can be associated with one piece of source code, and the platform (Android, Windows Phone, etc.) will automatically select the correct XML format, for example, screen insensitivity , orientation , etc.
  • The following is the answer to your question: why not html. In my opinion there are several reasons. Most importantly, XML has a strict structured structure , and XML can be limited to XML Schema . In fact, having an XML schema is great, because it also does not limit your document, but it also provides a kind of documentation of files inside XML. Someone reading this might think: HTML can have a strict structure as an XHTML specification. Yes, but XML has been developed for this.
  • The next aspect is that XML is more popular as HTML in layout / layout (Java EE, XAML, Android XML, etc.). This is like good practice.
  • In fact, you can create your application almost in HTML / JavaScript, but you need to use a specific structure that wraps your Platform application and transforms it into an independent Platfrom web application (for example, Sencha Framework).
0
source

Extensible Markup Language, the extensible part makes it much more universal. HTML is basically an implementation of the general concept of XML specifically for web browsers.

In addition, it is too bloated for the simple task of creating layouts, because it contains many tags and attributes (i.e. method , onclick , etc.) that determine the behavior of elements not only in their layout.

0
source

Source: https://habr.com/ru/post/1441216/


All Articles