To provide backward compatibility with older phones still running on Android 1.5 you might have to provide separate layout resources for Android 1.5 and Android 1.6+. Especially when dealing a lot with RelativeLayout, which was basically crap before Android 1.6.
Instead of having one res/layout folder we will create two new folders:
- res/layout-v3 for Android 1.5
- res/layout-v4 for Android 1.6 and higher
Now move all your files to
res/layout-v3 and test your application on various phones and emulators (which are running different Android versions). Whenever you see that there's a non-acceptable difference in the layout copy the responsible
.xml-file to the
res/layout-v4 folder and modify the file in both folders so that they work for
Android 1.5 and
Android 1.6 and higher again. Android will then pick the right layout resource during runtime depending on its current firmware version.
Bug in Android 2.0
There seems to be a bug in Android 2.0. Instead of picking the resource from
res/layout-v4 as it should and if it doesn't find it there then from
res/layout-v3, it expects the the resource wrongly in the default
res/layout folder. To make it work you should rename
res/layout-v3 back to
res/layout again (or just create a symlink). The second problem or bug that comes with it, is to provide the special resources for Android 2.0 or higher. Instead of providing those in
res/layout-v5 Android 2.0 expects wrongly
res/layout-v6. So just use this instead for now. The bug is fixed in Android 2.0.1, but there are still quite some Android 2.0 phones out there.
I hope this post is not too confusing ;-)