getIdentifier 方法会选择正确的可绘制资源吗?

does getIdentifier method pick the correct drawable resource?

我在 drawable、drawable-hdpi、drawable-xhdpi、drawable-xxhdpi 等下提供了不同尺寸的图像。我正在使用下面的代码片段来检索我 [=15= 中的图像资源 ID ] 应用

 int resid = res.getIdentifier("com.mypackage:drawable/" + selectedItem.getImageName(), null, null);
   imageFilePath = "com.mypackage:drawable/" + selectedItem.getImageName();

这是否会根据运行应用程序的设备的屏幕尺寸来选择适当资源的 ID? (例如:- 在 android phone 中 运行 时选择可绘制资源,在 android 选项卡中 运行 时选择 drawable-xxhdpi)

是的,如果相应的资源文件(在我的例子中是图像)位于相应的文件夹(drawable、drawable-hdpi、drawable-xhdpi、drawable-xxhdpi 等)中,getIdentifier 方法会根据设备选择相应的图像是 运行 应用程序。