For Layouts
First, you should start off by reading the official Supporting Multiple Screens Best Practices. There are a lot of good tips there, as well as a general idea on what you need to be looking for in terms of compatibility.
One thing I've found to be very helpful, which seems quite obvious, is to actually test your layout in various sized emulators. How does your layout look when expanded to 1024x768 (even though no device will have such a res)? How about when it's super tiny and square? Seeing how your layout stretches/contracts will help you tweak it to better fit all screens.
layout_weight
In layouts, android:layout_weight
is a powerful, but under-documented attribute. Using it, you can create layouts where components are sized in percentages to each other.
For example:
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:layout_weight="80"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:layout_weight="20"
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content />
</LinearLayout>
In this layout, the <EditText/>
will take up 80% of the available width, while the <Button/>
will take up 20% of the available width. Obviously, this should be used carefully so that all items can still be usable even if they are small.
<include />
Another helpful layout practice is to bundle up common bits of your layout into separate files and include them using <include layout="@layout/smaller_section" />
. That way, you can shuffle around other parts of the layout (say, for landscape), without having to keep entire parallel versions of the layout.