Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - detect small tablet vs big phone?

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.

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

like image 344
Bostone Avatar asked Apr 09 '12 22:04

Bostone


People also ask

How do I deal with different screen sizes on Android?

The best way to create a responsive layout is to use ConstraintLayout as the base layout in your UI. ConstraintLayout enables you to specify the position and size of each view according to spatial relationships with other views in the layout. All the views can then move and resize together as the screen size changes.

At what point does a phone become a tablet?

The main difference is the size of the screen. Smartphones usually have screen sizes between 4″/10cm and 7″/17cm, a tablet is anything over this.

Can I use a tablet instead of a cell phone?

Once you've established an internet connection, you really need only two things to make your tablet function as a smartphone: an app that makes use of VoIP (Voice over Internet Protocol) or VoLTE (Voice over LTE) wireless calling technology, and a pair of headphones.

Are tablets just big phones?

A tablet is a touch screen device like a phone with a much larger screen or a small laptop without the keyboard. Like phones and laptops, you can use tablets for entertainment, work, and other purposes.


2 Answers

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 );
    }
like image 131
waqaslam Avatar answered Oct 11 '22 11:10

waqaslam


Check out the documentation for Supporting Multiple Screens. You can follow a predetermined folder naming structure so that Android will load different layouts and drawables for different screen sizes/densities.

For example:

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
like image 43
wsanville Avatar answered Oct 11 '22 13:10

wsanville