سؤال

I am working on android app, i want that this app must fit on different screen sizes and densities. I have made files.xml files in res/layout by default, res/layout-small/xml files for supporting small screens such as QVGA (low density) ,res/layout-normal/xml files for supporting medium screens such as HVGA(medium density) and res/layout-large/xml files for large screens such as WVGA800(high density). When i run app initially on medium size screen such as 320x480 i-e HVGA it runs perfectly but when i run same app on large or small screen emulator it displays same layouts which were displayed on medium size screen and doesn't fit on the screen and vice versa. I havn't use absolute layout and used dp instead of px or sp or dip. I have tried alot but couldn't succeded. How should i handle that situation? Any idea?

هل كانت مفيدة؟

المحلول

A few things to try,

  1. Dump the actual screen size at run time to confirm the screen size is what you are expecting see Get screen dimensions in pixels

  2. Temporarily remove the contents of the res/layout folder to debug where the resources are being pulled from.

Generally you should be able to support QVGA and HVGA with the same layout resource but adaptable widths and heights, eg fill_parent etc. Then have a seperate layout for tablets.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top