本文介绍了Android的 - 检测小片与大的手机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

该应用程序我正在开发包含2个独立的布局:一种是面向普通电话,其他的小片如NOOKcolor。这是这是基于屏幕的宽度的分辨率(目前600dip)作出的决定。它看起来在角落伟大的,但可怕的HTC Rezound,其具有720×1280的显示。关于后者,无论更高的分辨率,一切(文字,图片等)看起来大得多,因此它得到所有揉成。

The app I'm developing contains 2 separate layouts: one is for the regular phones, other for small tablets such as NOOKcolor. The decision which is which is made based on the screen width resolution (currently 600dip). It looks great on Nook but terrible on HTC Rezound, which has a 720 x 1280 display. On the latter, regardless of higher resolution, everything (text, images, etc) look much larger so it gets all bunched up.

什么将是一个很好的方法来选择合适的设备?或许检测物理尺寸(4.3与7)与分辨率?

What would be a good approach to pick the right device? Perhaps detect physical size (4.3" vs 7") vs resolution?

推荐答案

使用下面的方法来检测设备的屏幕尺寸:

Use the following method to detect your device's screen size:

    /**
     * Checks if the screen size is equal or above given length
     * @param activity activity screen
     * @param screen_size diagonal size of screen, for example 7.0 inches
     * @return True if its equal or above, else false
     */
    public static boolean checkScreenSize(Activity activity, double screen_size)
    {
        Display display = activity.getWindowManager().getDefaultDisplay();
        DisplayMetrics displayMetrics = new DisplayMetrics();
        display.getMetrics(displayMetrics);

        int width = displayMetrics.widthPixels / displayMetrics.densityDpi;
        int height = displayMetrics.heightPixels / displayMetrics.densityDpi;

        double screenDiagonal = Math.sqrt( width * width + height * height );
        return (screenDiagonal >= screen_size );
    }

这篇关于Android的 - 检测小片与大的手机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:14