4

My application is supporting 3 type of density ldpi (120),mdpi(160),hdpi(320) and for that we have three folder for resources (ldpi,mdpi,hdpi).

But my problem is occurring in HTC sensation XE (540x960) having density ~256 dpi.and my resources is stretched.

In manifest file

<supports-screens android:xlargeScreens="false" /> 

means i am not supporting for xlarge screen so does 540x960 come in high density??. How can i overcome this problem???

Android Multiscreen Support issue says "You can also use a combination of density and size qualifiers but that still leaves some room for two different resolutions falling into the same bucket."

What should be the name of drawble folder for this kind of resolution?? or is there any other way to short out this issue.

EDIT : My problem is not with layout, my problem 540x960 come in HDPI but my hdpi drawbles are designed related to 480x800

Help me..

Thanks in advance..

Community
  • 1
  • 1
Bhavesh Hirpara
  • 22,255
  • 15
  • 63
  • 104
  • 1
    To make a layout that is specifically for 540x960 devices, use this solution: http://stackoverflow.com/a/10931395 – user2129417 Mar 03 '13 at 18:09

3 Answers3

6

you can use below combination for Layout for HTC sensation XE (540x960) :

res/layout-w540dp-h960dp/layout.xml 

this will use for pick layout for this device and for drawable it will pick image from hdpi because in this developer site 256 dp come in range of hdpi . http://developer.android.com/guide/practices/screens_support.html.

hope this will help you.

Ragunath Jawahar
  • 19,513
  • 22
  • 110
  • 155
Herry
  • 7,037
  • 7
  • 50
  • 80
  • I agree with your statement but my problem is not with the layouts because my layouts is almost same for all resolution, problem is drawable.HTC sensation come in the range of hdpi but my hdpi drawbles are designed for 480x800 that is not matching with 540x960 at all and it's stretched. – Bhavesh Hirpara May 08 '12 at 04:39
  • 1
    i think you may need to use .9 patch images that are may use for both 480x800 and 540x960. – Herry May 08 '12 at 04:41
  • I thought last night a lot about this issue, my some drawbles resources are very static and can not be make 9 patch.because they are very static.This can be major problem.:( – Bhavesh Hirpara May 08 '12 at 04:44
  • 1
    res/layout-w540dp-h960dp/layout are you sure it works. because i create an avd for HTC sensation having 540X960 hdpi But it takes layout from "layout" folder not from this one. – Suresh Sharma Apr 24 '13 at 11:09
  • What is your HTC Sensation android os Version? – Herry Apr 24 '13 at 13:38
2

Your problem is that you have designed your bitmaps for a particular screen size rather than screen density.

Plainly put, you should not do that. There are a huge number of different form factors and screen sizes out there, and you cannot hope to have graphics sized for all of them. So you fix this issue for 540x960 screens... what then with your users who are on 480x854 displays (most hdpi motorola devices)? Will you include different graphics for 1024x720 and 1280x720 displays if you're developing for that? What about 1280x800?

Granted - it can be a pain to deal with these issues, but that is the price we pay for diversity of devices. And Google has provided a fair amount of powerful tools at our disposal to deal with this.

When you are designing an app for Android, you need to think of the design as if you were designing a website - not a desktop (or IOS) program. All (or most) of the tricks that you use for designing a website also apply here - plus you have the density-awareness and 9.patch tools.

And if you really cannot adjust your graphics/layout to the screen without messing it up, you can always center the layout on the display (or align it left or right, depending on what you think looks best).


Edit:

As I mention above, the core to flexible UI design in Android is to think of your app like a web site. Roman Nurik has an article discussing this on the Android blog.

http://android-developers.blogspot.com/2011/09/thinking-like-web-designer.html

Apart from that, it is mostly covered by the Android site, etc.

http://developer.android.com/training/multiscreen/index.html

Using the right layouts and 9-patch images (not always - sometimes static images are better) will allow you to create designs that look good on all phones. But you have to realize that - like a website designed in a browser - you do not and can not have 100% control over how things are displayed on every single device. What you need to achieve is that it is still accessible and good-looking even when displayed on a device that you did not anticipate beforehand.

Michael A.
  • 4,163
  • 3
  • 28
  • 47
  • 480x854 is same as 480X800 so it's not problem..and 2nd thing is we don't support for extra large screen.problem is for 540x960 only and for some drawables only. – Bhavesh Hirpara May 08 '12 at 12:59
  • 1
    The principle remains the same; designing an app in this way is a bad idea on Android. And selecting away xlarge displays will not protect you from having to deal with this issue of multiple screen sizes. The Galaxy Nexus has a 1280x720 screen. The Galaxy Note runs 1280x800. There are 7" tablets with 1024x720 screens. None of these displays would be considered xlarge. – Michael A. May 08 '12 at 21:49
  • can you please tell me more (for my further application)..There are so many devices having different resolutions and comes in hdpi (Large screens not in xlarge screen) then for that how can i handle drawables for all the hdpi devices.All devices is having same drawable resources and that is hdpi.what is the master way??? – Bhavesh Hirpara May 09 '12 at 04:17
  • There is no master way to do this; it all depends on your specific design, and how you want to achieve this. But I've linked to the article from Nurik on the topic from last year. – Michael A. May 09 '12 at 08:46
1

You have to name the drawable as per your pixel density and the screen size. The calculation is here...

dpi = sqrt (540^2+960^2) / 4.3"(Device size) = ~256 dp = px / (dpi / 160) = 540 / (dpi / 160) = 330

The drawable will be named as drawable-sw330dp. I have tested this. And this works good. No problem with other drawables either. Layout Will be layout-sw330dp

Or you can try this by drawable-sw540p. I haven't tested it yet. But I guess it will work good. Layout Will be layout-sw540p

mAyA
  • 66
  • 6
  • DisplayMetrics displayMetrics=new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); Log.e("TAG","displayMetrics.density="+displayMetrics.density+",displayMetrics.densityDpi="+displayMetrics.densityDpi+",displayMetrics.scaledDensity="+displayMetrics.scaledDensity); displayMetrics.densityDpi gives something different from calculation, – Iftikar Urrhman Khan Feb 19 '15 at 10:46