Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supporting multiple screen size - Android

I am going to develop new application in Android. This application should only work in portrait (even for tablet). Also the UI and layout design should be similar on phones and tablet. We can't change the layout design for tablet as it has huge area to use. We have to stretch all the images to match phones. We can use nine patch. But I am little bit confused of using images in multiple drawables.

As per my analysis (may be wrong.. : ) ) the screens are divided into density and sizes. We can use the scaling ratio of 3:4:6:8. But this ratio is based on the density. But in my case I have to stretch the entire UI to fill the Tablet screen.

So what are the drawables that can be used for a app like this which can support multiple devices. And what are the screen sizes for which we have to design.

And this application needs nearly 100 layouts. So I am planning to maintain single layout and designing the layout using weight for each layout instead of using dimension.

Also if I used multiple APKs to support different screen size what are the drawables used to support 1. Small and Normal 2. Large 3. Xlarge

like image 300
Sniper Avatar asked Nov 21 '13 14:11

Sniper


2 Answers

I just did something very similar. To stretch the app without creating new layouts I used dimensions set in XML

res/values/dimensions.xml
res/values-sw600dp/dimensions.xml -> 7+ inches
res/values-sw720dp/dimensions.xml -> 10+ inches

Dimensions are resources files:

<dimen name="default_padding">11dp</dimen>

You can increase the dimensions by about 30% in the 600 and 720 file. Then simply used @dimen/default_padding in your layout and it will be scaled

Regarding images, either you make sure you have all your assets in all densities, or you set fixed size to you ImageView's and appropriate scaleType

like image 50
znat Avatar answered Nov 02 '22 23:11

znat


Firstly, you do NOT want to create multiple APKs to support multiple screen densities. Android provides all of the framework you need to support everything within one build, you just need to create the right resource hierarchy drawables with your desired densities.

So what exactly do you need... based on your question the following:

  • portrait mode: you can specify this in each Activity declared in your AndroidManifest file using the following:

    <activity android:name=".MainActivity" 
        android:label="@string/app_name"
        android:configChanges="orientation" > 
        ...
    </activity>
    

    NOTE: Per the Android docs, if you're targeting API >= 13, and you use the android:configChanges attribute you should also use the android:screenSize attribute to help specify size changes.

  • dimension sizes for various screens: as touched upon, this can also be handled in resources. This is your best way to use one common layout file but configure the layout for use on numerous devices. See http://developer.android.com/guide/topics/resources/more-resources.html#Dimension for how to use dimensions if you're unfamiliar

  • drawables: it sounds like this is the crux of your question. As you mentioned, using nine-patches will help you reduce your app footprint and fill in extra space (see here and here for more on nine-patches). The sizes you should support and the densities needed for those sizes are discussed in great detail in Android design docs, so much detail I could not even do it justice rehashing it here. I've provided links below to as many places as I could remember that this is discussed.

Good luck!

Here are links to Android design docs that you will find useful (some of which have been mentioned):

  • http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
  • http://developer.android.com/training/multiscreen/index.html
  • http://developer.android.com/guide/practices/screens_support.html
  • http://developer.android.com/design/style/devices-displays.html
like image 44
anddev84 Avatar answered Nov 03 '22 01:11

anddev84