Sorry for such a basic question but I am new to Android development, most my experience has been in c#
or c++
. Not sure if this is a Java thing or just Android but I have been disappointed to see that it is all held together with strings IE:
android:layout_height="wrap_content"
I would have expected to be more like:
android:layout_height=layout.wrap_content
which would make sure only valid options are used.
This seems to be the case for most things and it seems like bad practice. It also makes intellisense type stuff difficult also.
Can anyone explain why that approach has been taken? Is it a Java thing? or does it have its advantages for another reason?
Well, layouts in Android are defined via XML
, so it is neither Java nor Android. Since XML - is just a document markup language (just a set of rules for writing a document), it doesn't have anything like objects, methods, etc. It is not a programming language, so no enums here :)
That's essentially the whole point of XML (and any other markup language, like HTML f.i.) - it can (and should) be parsed no matter what system you use, what hardware and what OS - it is just a text written according to certain rules.
Internally Android parses this XML layout and transforms to Java objects (enums, ints, etc.)
Modern IDEs (Eclipse, Android Studio) help you a lot when you write Android XML layout - you don't need to remember all these XML values - intellisense suggests available text values for certain tags (like you have with enums) and when you mistyped some attribute - it starts complaining about invalid value. But this is not more than just an "on-the-fly" XML parser which just validates your input.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments