Android layouts start with <? Xml version ...?>

I am starting to develop applications for Android. My question is pretty simple. I cannot figure out if the xml files in the layout folder should start with:

<?xml version="1.0" encoding="utf-8"?> 

When I did the starting project, it was not there. But am I also reading a book that says it should be there?

What is the right way?

+6
source share
4 answers

Well, this ad should not be tagged by android, but it is rather xml syntax. It defines the XML version (1.0) and the encoding used (utf-8 = (8-bit Unicode conversion format)).

XML documents may contain non-ASCII characters, such as Norwegian Γ¦ ΓΈ Γ₯, or French Γͺ Γ¨ Γ©.

To avoid errors, XML encoding is specified, and the files are saved in Unicode.

These are some other examples of xml headers that you can experiment with or learn about:

 <?xml version="1.0" encoding="us-ascii"?> <?xml version="1.0" encoding="windows-1252"?> <?xml version="1.0" encoding="ISO-8859-1"?> <?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-16"?> 
+8
source

This is called the XML declaration line. Technically, this is not necessary, but it should be there, even if it is useful for text editors, etc. that can use the encoding attribute when displaying the file.

If you look at any of the Android samples provided by Google, or in fact, at any of the internal layouts, they all start with an XML declaration line.

See some examples here: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/layout/

+5
source

It is recommended that you store those tags at the beginning of your xml file. But, in my experience, their removal did not matter ...

Just make sure you have this present and it will work:

 <MY_VIEW_NAME xmlns:android="http://schemas.android.com/apk/res/android" 

MyViewName can be a LinearLayout FrameLayout RelativeLayout or even the view itself, for example. ImageView, TextView ... etc.

Whichever view or layout you start on the first line, you MUST have this URL.

+1
source

its not important to be there in xml .. its just the header of the xml file. it indicates the xml version and encoding format

+1
source

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


All Articles