I developed an Android application and published it in the Market. Now I want to make that same application for 10-inch tablets. The problem is when I run my build for 10-inch tablets, it works well but raises some UI issues involving display texts and layout heights. Textual titles look good in the handset version but very small in the tablet version.
How can I programmatically find out if the APK is running on handset, a 10-inch tablet, or a 7-inch tablet? And how can I maintain text sizes and view sizes based on screen sizes? I don’t want to make separate XML files for each resolution like (large, xlarge).
The standard way to do this if it’s just a matter of changing a few text sizes and dimensions is to use a single layout in which you reference dimension or style resources. For example, your layout can have one
TextViewwith its text size declared as:another view can have its height declared with:
and yet another view could have several properties grouped together in a style:
Then, in the
res/values-MODIFIERdirectory, you have, e.g.styles.xml:So you’d have tablet values in
res/values-xlargeand default values inres/values.If you need to make more drastic changes in your layout, you can use a separate layout, but reuse components with
<include>.