Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to develop one Android application for different screens? [closed]

I want to develop an application for Galaxy Tab and Android phones. The tab and phone UI are very different. Like in tab, we have used fragments, etc. and on the phone we want to use tabs.

I am aware that by using layout-small or layout-large I can show different UIs, but what about functionality?

How should I proceed? Is there a simple way to handle functionality also for different screens? Or is it better to create two applications finally?

like image 245
Harshad Avatar asked Dec 13 '22 10:12

Harshad


2 Answers

First be sure to read this recent blog post that gives an overview of how applications see different screen sizes and can adjust to them:

http://android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html

This post has some examples of basic adjustments -- providing different layout files for different screen sizes.

This is also something that the fragment APIs are intended to help with. If you are already writing your UI with fragments, you are most of the way there -- showing these in tabs does not require a totally different implementation, just use the fragments to populate the different tabs.

If you are targeting Android 3.0 or later, this is easy because the action bar already has simple mechanisms to have its tabs allow switching between fragments. This API demo provides a very simple example of its use:

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/ActionBarTabs.html

If you want to run on older versions of the platform, that is what the fragment APIs in the v4 support library are for. These allow you to write your app using fragments and still be able to run all the way down to Android 1.6 (API 4) of the platform. In MR2 we also added some sample code showing how you can use the support lib fragments with the old tab API.

Sample code for this is included in the now deprecated TabActivity class:

http://developer.android.com/reference/android/app/TabActivity.html

like image 200
hackbod Avatar answered Dec 31 '22 13:12

hackbod


There's no single answer to this - it's a broad topic.

One thing to keep in mind before you start, is that there's currently a lot of code floating around the web that assumes you can judge a screen size by the platform version: IE, everything up to Gingerbread is a phone, and Honeycomb (and up) is a tablet. This is a bad idea. Don't do this :) Also try to avoid a massive switch case that just executes different blocks of code based on width/height values you pull from the system. I'm not going to describe how to do that, others have already given that answer.

One thing to investigate is the Android Compatibility Package - It lets you use Fragments and Loaders (which were introduced in Honeycomb) in earlier versions of the Android platform. One common pattern this enables is to let you set up a nav fragment & content fragment which sit side-by-side on a Tablet (where there's room) but have the nav fragment switch over to the content fragment when an item is selected on a phone or smaller screen.

If you're just trying to have images that grow and shrink with screen size (that you're not drawing programmatically), the answer is 9-patches.

You also have the option, if it's appropriate for your application, of using Android Market's Multiple APK support. The linked page dives into how to set that up, and gives you a pretty solid description of when to use it and when you're better off with a single APK.

like image 33
Alexander Lucas Avatar answered Dec 31 '22 14:12

Alexander Lucas