Detecting screen density programmatically, pre-Hon

2019-08-17 18:23发布

I have a layout that works in certain phones, but in the Samsung Galaxy Ace doesn't work properly. I need to create a new layout for this phone (and similar) but I can't do it programmatically with this or this since this phone uses Android 2.2 and those solutions are for Android 3.2 and upwards. How can I create a new layout for this phone below Android 3.2?

2条回答
Lonely孤独者°
2楼-- · 2019-08-17 18:41

Have you tried this:

    DisplayMetrics displayMetrics = new DisplayMetrics();
    ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(
            displayMetrics);

    switch (displayMetrics.densityDpi) {
        case DisplayMetrics.DENSITY_HIGH: 
     ...
    }
查看更多
三岁会撩人
3楼-- · 2019-08-17 18:44

What I did in the end, was creating a folder called 'layout-sw320dp' which the Galaxy Nexus will take -while the Galaxy Ace will use the layout in the normal 'layout' folder- and I did the pertinent modifications for each phone/layout.

查看更多
登录 后发表回答