【发布时间】:2018-10-24 18:50:26
【问题描述】:
我有一个使用 Android 库 (com.appocaliptic.quizknife.core) 的 Android 项目 (com.appocaliptic.quizknife.app)。
我想做的是获取图片的资源ID,即图书馆。图片的路径是:res/drawable-xhdpi/fr_200_133.png
但是,所有尝试都使用 getIdentifier 结果为 0。问题出在哪里?
resId = getResources().getIdentifier("fr_200_133", "drawable", "com.appocaliptic.quizknife.core");
resId = getResources().getIdentifier("com.appocaliptic.quizknife.core:drawable/"+"fr_200_133", null, null);
resId = getResources().getIdentifier("drawable/fr_200_133", null, "com.appocaliptic.quizknife.core");
已编辑:
啊,在R.java中有drawable和corresponding属性。
【问题讨论】:
-
您正在测试的系统是否有 xhdpi 分辨率的屏幕?
-
@Squonk - 在检索 id 本身时,这无关紧要;仅在检索与 id 关联的可绘制对象时。此外,对于可绘制资源,系统会找到best match,因此即使在 ldpi 设备上也会使用 xhdpi 资源(缩放后)。
-
@TedHopp :是的,同意 - 我忘记了可绘制资源的最佳匹配。