Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
支持9.6英寸和10.1英寸android平板电脑_Android - Fatal编程技术网

支持9.6英寸和10.1英寸android平板电脑

支持9.6英寸和10.1英寸android平板电脑,android,Android,我必须支持屏幕分辨率为1280*800(dp)(KitKat)和1280*752(dp)(棒棒糖)的android设备。第一款是10.1英寸的平板电脑,第二款是9.6英寸的平板电脑 我对所有设备使用相同的布局,并使用外部化尺寸调整不同屏幕的布局 但我无法使用“values-sw720dp”和“values-sw800dp”来分离设备。如果我使用sw800dp,它们都使用sw800dp dimen文件夹中的dimen值 如何为这两台设备提供单独的尺寸?以编程方式获取设备的screnn英寸和应用尺寸

我必须支持屏幕分辨率为1280*800(dp)(KitKat)和1280*752(dp)(棒棒糖)的android设备。第一款是10.1英寸的平板电脑,第二款是9.6英寸的平板电脑

我对所有设备使用相同的布局,并使用外部化尺寸调整不同屏幕的布局

但我无法使用“values-sw720dp”和“values-sw800dp”来分离设备。如果我使用sw800dp,它们都使用sw800dp dimen文件夹中的dimen值


如何为这两台设备提供单独的尺寸?

以编程方式获取设备的screnn英寸和应用尺寸

public static double getDeviceInches(Activity activity) {
    DisplayMetrics metrics = getMetrics(activity);
    int widthPixels = metrics.widthPixels;
    int heightPixels = metrics.heightPixels;

    float widthDpi = metrics.xdpi;
    float heightDpi = metrics.ydpi;

    float widthInches = widthPixels / widthDpi;
    float heightInches = heightPixels / heightDpi;

    return getDiagonalInches(widthInches, heightInches);
}

private static double getDiagonalInches(float widthInches, float heightInches) {
     double diagonalInches = Math.sqrt((widthInches * widthInches) + (heightInches * heightInches));
     float roundedValue = (float) Math.round(diagonalInches);
     return (double)roundedValue;
}

//From this, we can get the information required to size the display:
private static DisplayMetrics getMetrics(Activity activity) {
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    return metrics;
}

public static int convertDpToPx(Context context, int value) {
    // Get the screen's density scale
    final float scale = context.getResources().getDisplayMetrics().density;
    // Convert the dps to pixels, based on density scale(0.5f is for rounding up value) (arrowWidth is 50dp)
    int pxValue= (int) (value * scale + 0.5f);
    return pxValue;
}

将上述代码放在实用程序类中,并从活动或片段类调用getDeviceInches方法

@KushPatel为什么最小宽度为752dp的设备从values-sw800dp文件夹中获取dimen值?