Android UI design based on screen resolution - android

I'm looking to make an Android app that changes the look of the UI based on the device it's shown on (4 inch phone, 7inch tablet and 10inch tablet). I know you have the fragments API and it's probably that which I should use for this, but all the examples I've seen just have 2 activities sitting side by side and the code is a bit OTT for my needs (they have events passing between them etc).
Here is the comparison between a 4 inch device and a 7 inch device and how the different UI elements should move around (also note that element A can change design between the two devices).
Any ideas on how I would go about doing this, or if anyone has any sample code that would be fantastic!

I think you should probably design different xml for each size. You can use the qualifier in the layout dir for different screen size. http://developer.android.com/guide/topics/resources/providing-resources.html#AliasResources

You can use different directory for different size :
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
and for more information :
http://developer.android.com/guide/practices/screens_support.html
Good Luck,,, :D

See also Fragments for Android 3.0+.

Related

How does android choose the right layout/drawable for the correct screen resolution?

I that When starting an android application, android makes a good "guess" as to which layout/drawable to use depending on the screen size. However, I was wondering where it chooses this from? I ask this because I have quite a few layouts which don't all work. I read on the android website that you can make a folder called layout-xhdpi, layout-ldpi... etc. But does android automatically look for layout-xhdpi or layout-ldpi or do I need to specify that anywhere?
Same goes for drawables. When creating a new application in Eclispe it makes automatically drawables folders for you but does this necessarily mean it looks for those.
Conclusion:
Where does android look for alternative screen sizes and how/where can I change that?
Create following layout folder
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density

Application to support multiple screen resolutions

I have 3 layout folders in my project:
1. layout
2. layout-large
3. layout-small
and as of now i don't have anything in layout-small but layout has layouts with small dimensions and layout-large has layouts with large dimensions.
The problem is:
when i test my app on a 240x320 it uses layouts from layout
when i test my app on a 480x800 even now it uses layouts from layout
Is it because thought i have layout-large, 480x800 doesn't fall into large screens, hence uses the default layout folder?
If that is the case, how can i make layouts for Normal Screens there is nothing like layout-normal or layout-medium.
Moreover, if i design my layout for HVGA (320x480) it should work perfectly for WVGA800 (480x800) since they both fall under same screen size, only density changes. And i am using dp everywhere. Am i right?
any help appreciated.
When it comes to xlarge, large and small then it is depending on size(inches) not on dpi of your device
see below for specification
Additionally DPI is basically for Drawables while SIZE is for Layout.
Just use the following details it may work but i am not sure..
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
Just try....
You should check this developer page out it helped me alot. http://developer.android.com/guide/practices/screens_support.html
Even if they have different resolution or screen size that doesnt mean that they have different pixel density. For example a large screen may have less pixel density than a smaller screen.
Another example would be the Samsung Galaxy tab which is 10.1 inch but is still mdpi-large and Nexus One which is less than 5 inch but uses hdpi.
Best of luck
I think I got what is going wrong with you........ lets try this.
suppose you are going to make the application compatible for 480x800 resolution.So for that first of all create two folder for it i.e.
1.layout-sw480dp this is for landscape.
2.layout-sw480dp-port for portrait mode.
Now,put all layout of the resolution of 480X800 in it.you see it will run easily on the particular resolution.
Note:- point here to be noted that for any device resolution let A X B. the name of the layout folder is goes like this.
1.layout-swAdp.
2.layout-swAdp-port.
here "A" is the screen resolution height value of device.
i hope it work for you.

Using different resources for different layouts. Layout distinctions

I've got a layout-normal and layout-large. Additionally, I provide several splash images with different resolution: 480x800 and 1280x800.
My problems are:
In my task it's said that I must distinguish layouts based on device resolutions(one for 480x800 and the other for 1280x800). Is there any possibility to implement it ? Taking in consideration an assumption that handsets have 480x800 resolutions and tablets - 1280x800 and higher, I could implement this scheme but I'm not sure that it's true.
I've created a test project where I attempted to distinguish layouts based on size, but I can't make android use 480x800 image for layout-normal and 1280x800 image for layout-large: in both cases it shows the 480x800 image. I guess, it's because of size, in case of a device, not equals resolution, in case of an image. However, I need to provide completely different looks for 480x800 and 1280x800. what are my options here ?
Thanks.
PS I'm building against Android 2.3.
You have the "Supporting Multiple screens" documentation that helps on that matter.
For example, the following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for medium, high, and extra high density screens.
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density

how to i develop android application to work in different screen resolutions

I,m working on android project.
Actually i have develop on small app in honeycomb with resolution(1024*600), when am running the same app in different resolution let say android 2.2(froyo) screen the alignment of images in app screen changes.
Note:Images that are place in xml file are manual arranged(no wrapper thing used for width and height)
Please help me out this question asap..
regards,
Murali...G
Mainly we need to look up is the usage of UI patterns like action bar, Dashboard etc.
But the key point is you should use less static images and as you also use tablet. You should've used Fragments(Of course you would ve done. In case if you have done. Please do it).
Also use 9 patch images or colors for backgrounds. If you are using different images then. You need to keep images for different density.
Maybe all I say is abstract as this question is a abstract one. There is no one line answer for this. As this is a process by itself.
//design your xml in this way
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
Low density Small screens QVGA 240x320
res/layout-small-ldpi
res/layout-small-land-ldpi
Low density Normal screens WVGA400 240x400 (x432)
res/layout-ldpi
res/layout-land-ldpi
Medium density Normal screens HVGA 320x480
res/layout-mdpi
res/layout-land-mdpi
Medium density Large screens HVGA 320x480
res/layout-large-mdpi
res/layout-large-land-mdpi
High density Normal screens WVGA800 480x800 (x854)
res/layout-hdpi
res/layout-land-hdpi
Xoom (medium density large but 1280x800 res)
Check this Android class:
http://developer.android.com/training/multiscreen/index.html

Testing Android application with different-sized screens

I have a question for you guys about multiple screens.
I am testing an Android application for different-sized screens using emulator. The application have been initially developed for resolution 320*480. I know it is not good and I have problems in my code. Moreover, I have used pixels in some places of code instead of dip. You see, I am not a professional in Android. In any case, there is no problem for devices with resolution 320*480 and 480*800. For the second one the application looks stretched. According to documentation it should be so. But, when I am trying resolutions 540*960 or 1024*600 the application occupies just a part of screen and it seems to be 320*480. The question is: why it didn't stretched the application to the whole screen? How can I do it?
I have read Supporting Multiple Screens guide here: http://developer.android.com/guide/practices/screens_support.html#dips-pels, but I haven't found an answer for my question.
Have you go through this lines in the link given by you?
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size i
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
for different size devices, make different folder as given above like layout-small,layout-large.. and put your designing xml in that.
Hope this help you.

Categories

Resources