1

我正在使用以下代码从用户的图库中选择与屏幕的显示宽度/高度匹配的裁剪图像(以便能够将其设置为我的全屏活动的背景):

    int PHOTO_WIDTH = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
    int PHOTO_HEIGHT = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight();
    Intent intent = new Intent(Intent.ACTION_PICK, null);
    intent.setType("image/*");
    intent.putExtra("crop", "true");
    intent.putExtra("outputX", PHOTO_WIDTH);
    intent.putExtra("outputY", PHOTO_HEIGHT);

这适用于某些设备,但不适用于其他设备(即使它们具有相同的 xhpdi 密度)。

如何获取当前屏幕比例(包括状态栏,不包括软键按钮行)并将其设置为 PICK 意图?

4

2 回答 2

0

我最终只是使用显示宽度/高度作为aspect_xaspect_y参数的值:

Display display = getWindowManager().getDefaultDisplay();
int aspect_x = display.getWidth();
int aspect_y = display.getHeight();
于 2013-09-07T13:39:42.220 回答
0

您还可以使用Configuration提供的值:

public int screenHeightDp 可用屏幕空间的当前高度,以dp为单位,对应屏幕高度资源限定符。

public int screenWidthDp 可用屏幕空间的当前宽度,以dp为单位,对应屏幕宽度资源限定符。

因为您对比率感兴趣,所以单位无关紧要(dp 而不是 px)。你可以这样配置:

Configuration config = getResources().getConfiguration();
于 2013-09-11T12:23:05.970 回答