为一组view设置相对应的一组图片资源时用到数组。

1.在string.xml中定义.pic1234是已放入drawable文件夹下的图片。

<string-array name="main_tab_images">
        <item>@drawable/pic1</item>
        <item>@drawable/pic2</item>
        <item>@drawable/pic3</item>
        <item>@drawable/pic4</item>
</string-array>

2.获取图片的id

TypedArray ar = context.getResources().obtainTypedArray(R.array.actions_images);
    int len = ar.length();    
    int[] resIds = new int[len];    
    for (int i = 0; i < len; i++){
        resIds[i] = ar.getResourceId(i, 0);//资源的id

 }

http://stackoverflow.com/questions/6945678/android-storing-r-drawable-ids-in-xml-array

相关文章:

  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2021-12-26
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案