Android - detects a small tablet with a large phone?

The application I'm developing contains 2 separate layouts: one for regular phones, the other for small tablets like NOOKcolor. A solution that runs based on the resolution of the screen width (currently 600dip). It looks great on the Nook, but terrible on the HTC Rezound, which has a 720 x 1280 display. On the latter, regardless of the higher resolution, everything (text, images, etc.) looks a lot bigger, so it gets complicated.

What would be a good approach to choosing the right device? Perhaps determine the physical size (4.3 "versus 7") versus resolution?

+5
source share
2 answers

:

    /**
     * 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 );
    }
+4

. , Android /.

:

res/layout/my_layout.xml             // layout for normal screen size ("default")
res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

res/drawable-mdpi/my_icon.png        // bitmap for medium density
res/drawable-hdpi/my_icon.png        // bitmap for high density
res/drawable-xhdpi/my_icon.png       // bitmap for extra high density
+1

All Articles