-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|204|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Text and GUI's


 
Cower
Created : 25 August 2013
Edited : 25 August 2013
System : Android
Language : Other

Scala Relative Layout Traits

Some traits and an object to make working with Android's relative layout parameters easier, provided you're using Scala.

This was mostly intended as an experiment to see if I could make working with view layout in Scala simpler than using Android's godawful XML resources (which have their uses, but are a huge pain in the neck for a lot of reasons). Basically, if you need to create a subview of a relative layout in Android, you're probably already screaming in pain because Java is terrible and Android is heavily in favor of doing things the Java way — meaning long-winded and needlessly complicated.

If you need to do that and don't want to suffer, 1) you're already using Scala, so that's a step, and 2) you can use this to write out stuff like the following:



That will net you a text view with a button to its side, both baseline-aligned, and so on. It's quite a bit more readable than XML. I might also just build up something to generate XML from far-more-readable Scala (or do it in Ruby), so that way you can use the same language for both runtime and compile-time layout. For example:



Anyway, source is below. It's all documented. Should be pretty clear what it does, since it's not doing anything really weird — all the magical stuff is just Scala allowing me to have infix methods and such (postfix methods are also allowed but disabled by default because it's really easy to abuse and doesn't really contribute anything, so I don't recommend enabling it). Basically, the code's all really simple.


 

Comments