开发者

Android: how to deal with devices with unfortunate dpi classification?

My application has a toolbar with ImageButtons that I use as application buttons. I specify the layout_width and layout_height of开发者_开发问答 the buttons as 12mm. (12mm * 160dpi) / (25.4 mm/in ) = 75.9pix, on a 160dpi device. Similarly, it will be 113.4pix on a 240dpi device. So, I would be inclined to make my mdpi drawables about 60x60 and my hdpi drawables about 90x90 (to allow for some margins and such).

However, I run into an issue on devices like my Samsung Galaxy Tab. Which, unfortunately, is classified as hdpi despite being only 170dpi. At 170dpi, 12 mm = 80.3pix. But, because it is hdpi, it will use the 90x90 icon, which is far too big.

My inclination is forgo the ldpi/mdpi/hdpi framework, and just package icons at 30x30, 40x40, 50x50... 100x100. And, in code, choose which one to use based on the stated dpi on the device (which is also inaccurate, but far less so). However, this seems hard to maintain and just generally inefficient.

Any advice on how to handle this situation?


Don't use the absolute size units like mm and in. With the way current devices are, they can't be relied on. Only use px and dp.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜