有没有办法确定当前设备的屏幕尺寸类别,如小,普通,大,xlarge?
不是密度,而是屏幕尺寸.
如何检测设备是小还是大?我不需要检测是否是平板电脑。
这个概念取自https://devblogs.microsoft.com/xamarin/styling-for-multiple-device-resolutions/
我们使用下面的方法并相应地加载适当的样式,但是因为我没有考虑密度,所以它不准确。
我怎样才能改进或重写这个方法,以便它给我一个更好的结果,并更准确地检测设备是大还是小。
当前的
const int smallWightResolution = 768;
const int smallHeightResolution = 1280;
public static bool IsASmallDevice()
{
// Get Metrics
var mainDisplayInfo = Xamarin.Essentials.DeviceDisplay.MainDisplayInfo;
// Width (in pixels)
var width = mainDisplayInfo.Width;
// Height (in pixels)
var height = mainDisplayInfo.Height;
return (width <= smallWightResolution && height <= smallHeightResolution);
}
Run Code Online (Sandbox Code Playgroud)
尝试使用密度但不知道公式是什么
public static bool IsSmallDevice()
{
//we don't support tablet so tablet don't apply.
int smallWidthResolution = 768;
int smallHeightResolution = 1280;
double screenWidth;
double screenHeight;
bool …Run Code Online (Sandbox Code Playgroud) 我试图在我的代码中检测7"平板电脑(即Kindle Fire和Nook Color).但是,仅测试1024x600的最小尺寸并不好,因为那时Galaxy Nexus也会通过这个测试.任何人都有检测这个的经验那种信息?
谢谢,伊戈尔
编辑: 我找到了一种方法来检测Kindle Fire和Nook Color设备,代码如下:
Activity activity = (Activity) activityContext;
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
int height = activity.getWindowManager().getDefaultDisplay().getHeight();
if ((width == 1024 && height == 600) || (width == 600 && height == 1024)) {
//Detects 7" tablets: i.e. Kindle Fire & Nook Color
isTablet = true;
}
Run Code Online (Sandbox Code Playgroud)