在 xhdpi 设备上使用 xxhdpi
Use xxhdpi on xhdpi device
我创建了我的应用程序以支持从 hdpi
到 xxxdpi
的屏幕,一切都运行完美。图像的显示就像他们应该的那样。但是,现在我遇到了小米 Max 3 的问题。它有 6.9" 显示屏,分辨率仅为 1080x2160
,分辨率约为 350 dpi。属于 xhdpi
类别(通常 720p
屏幕),现在我的图像比它们应该的要小。有什么方法可以强制使用带有代码的 drawable-xxhdpi
文件夹?
只需创建另一个文件,如:
drawable-xxxdpi/example.png
drawable-anydpi-v21/example.xml
和 link 来自 anydpi xml 代码的图像文件,用于支持所有屏幕尺寸。
从官方网站查看更多信息或访问
好的,感谢 Md.Abdullah 我找到了解决方案。
您无法选择要使用的资源文件夹,但可以使用 getDrawableForDensity()
方法从文件夹中使用特定资源。这就是我所做的:
int width = Resources.getSystem().getDisplayMetrics().widthPixels;
int dpi = getResources().getDisplayMetrics().densityDpi;
int imageID = R.drawable.YOURIMAGE;
if (width > VALUE && dpi < VALUE) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
Drawable drawable = getResources().getDrawableForDensity(imageId, DisplayMetrics.DENSITY_XXHIGH);
//you will probably need to adjust width & height of your ImageView, but since the image
//will keep its aspect ratio, you only have to change width | heigth
YOURIMAGEVIEW.setAdjustViewBounds(true);
YOURIMAGEVIEW.setMaxWidth(VALUE);
YOURIMAGEVIEW.setImageDrawable(drawable);
}
}
我创建了我的应用程序以支持从 hdpi
到 xxxdpi
的屏幕,一切都运行完美。图像的显示就像他们应该的那样。但是,现在我遇到了小米 Max 3 的问题。它有 6.9" 显示屏,分辨率仅为 1080x2160
,分辨率约为 350 dpi。属于 xhdpi
类别(通常 720p
屏幕),现在我的图像比它们应该的要小。有什么方法可以强制使用带有代码的 drawable-xxhdpi
文件夹?
只需创建另一个文件,如:
drawable-xxxdpi/example.png
drawable-anydpi-v21/example.xml
和 link 来自 anydpi xml 代码的图像文件,用于支持所有屏幕尺寸。
从官方网站查看更多信息或访问
好的,感谢 Md.Abdullah 我找到了解决方案。
您无法选择要使用的资源文件夹,但可以使用 getDrawableForDensity()
方法从文件夹中使用特定资源。这就是我所做的:
int width = Resources.getSystem().getDisplayMetrics().widthPixels;
int dpi = getResources().getDisplayMetrics().densityDpi;
int imageID = R.drawable.YOURIMAGE;
if (width > VALUE && dpi < VALUE) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
Drawable drawable = getResources().getDrawableForDensity(imageId, DisplayMetrics.DENSITY_XXHIGH);
//you will probably need to adjust width & height of your ImageView, but since the image
//will keep its aspect ratio, you only have to change width | heigth
YOURIMAGEVIEW.setAdjustViewBounds(true);
YOURIMAGEVIEW.setMaxWidth(VALUE);
YOURIMAGEVIEW.setImageDrawable(drawable);
}
}