Thursday, February 10, 2011

Accelerating Android XML Layouts with AutoHotkey - NOW WITH VIDEO!

I know that building your XML layouts can be frustrating at times. This won't magically build your UI's for you, but it will speed you on your way.
If you haven't heard of AutoHotkey, go and learn about it: It's one of the most useful tools out there. The basic concept is that you can program your own hotkeys for use all over windows. You can manipulate text, replace text, call other macros and scripts, build custom gui's and much more. This is only available for Windows, sorry everyone else. You will need to download and install this application first.
The Script
AutoHotkey is designed to allow you to write your own custom scripts and will auto-load any scripts on your machine with the .ahk extension. You can get my script here: android helper script. Once you have AutoHotkey installed, just download my script, rename it with an .ahk extension, double click on it and you'll be good to go.
How it works

Once the script is installed go into Eclipse or whatever other environment you code in and create a new xml layout file. Call it test_layout.xml or something. Once there follow these steps:
  • type: xml_heading^
  • press enter
  • type: relative_layout^
  • press enter
  • move your cursor to right after the text "
  • make a few lines inside your relative layout and indent and type: button^
  • press enter
  • type: image_view^
  • press enter
You get the idea. Here is a list of all the XML elements the script can input:
  • LinearLayout
  • RelativeLayout
  • FrameLayout
  • WebView
  • Button
  • ImageView
  • EditText
  • TextView
  • TableLayout
It can also insert some other random stuff:
  • xml heading thing at the top of an xml document(xml_heading^)
  • android namespace(android_namespace^)
  • the onCreate method in an activity. I hate typing that out every time! (on_create^)
That's it so far. For the layouts and widgets, the format for the hotkey replacements is just underscored names. If you add to the script, be kind and post it back to this thread. Thanks for reading. Enjoy

Update: I've uploaded a screen cast to YouTube.