Android XML Code format

It’s been a while since I last posted something about android programming.
From my point of view, this is a great thing, there is an untold story lying here! :)

Working with the Android UI requires a lot of XML “syntaxing”. (I’m sorry, I do not like the use of the words “programming” or “develpment” for XML).
Eclipse was a beautiful feature, called “Code formatter” where you press Ctrl + Shift + F (Format) and it nicely formats your code.
It works like a charm as long as the code is Java. When the code is XML, it does tide the code, but it is still non easily readable.

example of formatted but not well readable XML code:

Fortunately, there is a way for the eclipse code formatter to tide the XML code even more and make it way more readable.
Just go to Preferences -> XML -> XML Files -> Editor and check the “Split multiple attributes each on a new line”.

Now you have this:

enjoy! =)

Share

Android shape xml example

Shapes in Android are extremely useful but there are not enough examples.

The values for the shape attribute are: rectangle, oval, line and ring.

Here is a simple (and ugly) example but you can get the point:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
	android:shape="rectangle">

        <solid android:color="#ff0000"/>

	<gradient android:startColor="#ffffff" android:endColor="#000000"
		android:angle="180" />


	<stroke android:width="1dp" android:color="#FF000000"
		android:dashWidth="1dp" android:dashGap="2dp" />
         <!-- or -->
	<stroke android:width="1dp" android:color="#FF00FF00" />


	<padding android:left="7dp" android:top="7dp" android:right="7dp"
		android:bottom="7dp" />

	<corners android:bottomRightRadius="9dip"
		android:bottomLeftRadius="9dip" android:topLeftRadius="9dip"
		android:topRightRadius="9dip" />

</shape>

Check the documentation here for more details.

Share