从字符串数组中的android参考绘制字符串、组中、android

由网友(孤单少年)分享简介:我将如何引用从字符串XML文件绘制资源?我想做的事情how would I reference a drawable resource from the string xml file?I want to do@drawable/my_i...

我将如何引用从字符串XML文件绘制资源? 我想做的事情

how would I reference a drawable resource from the string xml file? I want to do

<string-array name="my_array">
<item>@drawable/my_image</item>
...

我将如何做呢?

How would I do that?

推荐答案

对于可绘IDS阵列,不使用字符串数组只需使用&LT;阵&GT;

for arrays of drawables ids, don't use string array just use <array>

然后使用它们,获得了 TypedArray 如果ID

then to use them, get a TypedArray if the ids

TypedArray images = getResources().obtainTypedArray(R.array.my_image_ids);
int resourceId = images.getResourceId(id, -1);

和当您使用资源ID和阵列就完成了循环利用,不要忘记

and don't forget when you're done with the resource id and array to recycle it

images.recycle();
阅读全文

相关推荐

最新文章