Tablet or Phone - Android

后端 未结 30 2500
难免孤独
难免孤独 2020-11-22 08:33

Is there a way to check if the user is using a tablet or a phone? I\'ve got problems with my tilt function and my new tablet (Transformer)

30条回答
  •  迷失自我
    2020-11-22 09:16

    For me the distinction between phone and tablet is not size of device and/or pixel density, which will change with technology and taste, but rather the screen ratio. If I'm displaying a screen of text I need to know if, say, 15 long lines are needed (phone) vs 20 shorter lines (tablet). For my game I use the following for a ballpark estimation of the rectangle my software will be dealing with:

        Rect surfaceRect = getHolder().getSurfaceFrame();
        screenWidth = surfaceRect.width();
        screenHeight = surfaceRect.height();
        screenWidthF = (float) screenWidth;
        screenHeightF = (float) screenHeight;
        widthheightratio = screenWidthF/screenHeightF;
        if(widthheightratio>=1.5) {
            isTablet=false;
        }else {
            isTablet=true;
        }
    

提交回复
热议问题