相关疑难解决方法(0)

如何使用代码确定设备屏幕大小类别(小,普通,大,xlarge)?

有没有办法确定当前设备的屏幕尺寸类别,如小,普通,大,xlarge?

不是密度,而是屏幕尺寸.

android screen android-screen-support

306
推荐指数
8
解决办法
11万
查看次数

如何以xamarin形式检测设备是大还是小

如何检测设备是小还是大?我不需要检测是否是平板电脑。

这个概念取自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)

xamarin.forms xamarin.essentials

5
推荐指数
1
解决办法
2117
查看次数

如何在代码中检测7"Android平板电脑

我试图在我的代码中检测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)

android android-screen kindle-fire

2
推荐指数
1
解决办法
3013
查看次数