In Android, you create styles (which is analogous to CSS), externalize your resources, and use what Android calls resource qualifiers to adapt your design to different form factors.
If you have a web programming background, this will feel familiar. If not, the idea is that your view automatically scales to suit the amount of space it has and you define how that view should adapt to new sizes.
Don't base you designs on specific devices or device categories, rather think about the natural separation or breaking lines for your views. There is no "phone" or "tablet", they are just devices in a continuum.
Responsive design, as opposed to pixel-perfect designs, from the start will make it a lot easier to scale your views.
Android dynamically selects resources at runtime that are best suited to the device running the application. You can set up alternatives for things like orientations, hardware, languages, locations, view sizes, and more. It frees you from the burden of figuring out in code what resource you should be showing if you use Android's system to do it for you.
Externalizing resources, such as images, strings, dimensions, styles, themes, and layout makes it much easier to maintain and scale your views.
This is the heart of the Android - there are no guarantees of what your app will run on, so you need to create the most flexible app and views possible to avoid headaches from hardcoded values.
The Activity
class provides helper methods to get these resources such as getString(R.string.name)
and getDrawable(R.drawable.name)
. There's also a method getResources()
. Some of these are available in the Fragment
class and you can always ask for the activity's resources by calling getActivity().getResources()
.
Use relative positioning when laying out your views so that they adapt well when running on different screen sizes. RelativeLayout
and LinearLayout
are great choices.
Use wrap_content
and match_parent
whenever possible when defining the layout_height
and layout_width
of your views. wrap_content
tells the system to measure the view at inflation and render the widget with just enough space to contain it. On the other hand, match_parent
says take up all the available width and height when rendering this view.