Multiple screens for HTC Desire and HTC Sensation [closed]

為{幸葍}努か 提交于 2019-12-12 04:46:34

问题


The thing I want to do is to have different layout for the Sensation and Desire models.

I read things about programming for multiple screens and providing resources for different screen size and density, but this sensation resolutions drive me crazy . I have a layout that works perfectly on HTC Desire; they are placed in the layout and the drawings are placed in hdpi. Everything is working perfectly. The problem comes when I try to run the app on the Sensation, everything is misplaced and looks very ugly.

My question is where to put the Sensation layouts ? What qualifier name should I use for Sensation?


回答1:


Try finding the resolution and the density of the device (Sensation) using the following code.

    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics dm = new DisplayMetrics();
    display.getMetrics(dm);

    int width = display.getWidth();
    int height = display.getHeight();
    int density = dm.densityDpi;
    String densityString = null;

    if(density == DisplayMetrics.DENSITY_HIGH) {
        densityString = "HDPI";
    } else if(density == DisplayMetrics.DENSITY_MEDIUM) {
        densityString = "MDPI";
    } else if(density == DisplayMetrics.DENSITY_LOW) {
        densityString = "LDPI";
    }

Then use you appropriate resource name qualifiers for the drawable and layout folders as in Multiple Screen Support. (e.g.) drawable-large-hdpi, layout-large-hdpi

This is not feasible all the times, since you won't have access to all the devices out there. So it's better to create AVDs with different display configurations based on the table depicted in How to Test Your Application on Multiple Screens from the above given link.



来源:https://stackoverflow.com/questions/7316160/multiple-screens-for-htc-desire-and-htc-sensation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!