在xhdpi设备上使用xxhdpi

问题描述 投票:0回答:2

我创建了我的应用程序,以支持从hdpixxxdpi的屏幕,一切都很完美。图像显示就像它们应该的那样。但是,现在我对小米米麦克斯3有一个问题。它有6,9“显示器,分辨率只有1080x2160,给出~350 dpi。这属于xhdpi类别(通常是720p屏幕),现在我的图像小了然后他们应该是。有没有办法强制使用drawable-xxhdpi文件夹与代码?

android drawable dpi
2个回答
0
投票

只需创建另一个文件,如:

可绘制-xxxdpi / example.png

抽拉-anydpi-V21 /的example.xml

并从anydpi xml代码链接您的图像文件,以支持每个屏幕大小。从官方网站上查看更多信息或访问What Is The Difference Between -anydpi And -nodpi?


0
投票

好的,多亏了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);
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.