Android Why is all the layout done with strings not enum

AndrewT

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?

Pavel Dudka

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.

edited at
0

Comments

0 comments
Login to comment

Related

Why is make printing "make: Nothing to be done for `all'."?

Check if Flags Enum containts all strings

disable all elements in a layout - Android

Use Strings with placeholder in XML layout android

Enum of strings

PyQt Layout seems not to work - why all is overlayed?

Why is my Android phone layout different then my layout on Android Studio?

How to set enum attribute by value instead of name in Android Layout?

why all date strings are changed into numbers?

Why to cast all the values in an object to strings in Javascript?

Android Studio Linear Layout Not showing at all

Android constraint layout: resize images for all resolutions

Android layouts - one layout for all screen sizes?

Get all Buttons In table layout in android Studio

android how to set buttons in layout for all resolution

Android - How to remove table layout and and all imageviews in it?

Android XML Layout - ImageView taking all space

How to access resource strings from enum's ToString in Android?

Why do layout params work in Android Programming?

Why is my layout not showing in Android Studio?

Why layout editor in android studio working incorrectly?

Why is 'All' getting removed from my enum list in Bot Framework

Name of the layout or how it's done?

Are all strings of strings.xml are always available in heap memory in Android?

Determining all workers are done

ocamlbuild: Nothing to be done for `all'

Check for all requests to be done

Why does a "customised Enum constructor" return the info of all the other Enum type?

Are all layout elements that are available on Android Phones available on Android Wear?

TOP Ranking

HotTag

Archive