二、建立drawable.xml
<resources>
<array name="res_mood_image">
<item>@drawable/face1</item>
<item>@drawable/face2</item>
<item>@drawable/face3</item>
<item>@drawable/face4</item>
<item>@drawable/face5</item>
<item>@drawable/face6</item>
<item>@drawable/face7</item>
<item>@drawable/face8</item>
<item>@drawable/face9</item>
<item>@drawable/face10</item>
<item>@drawable/face11</item>
<item>@drawable/face12</item>
<item>@drawable/face13</item>
<item>@drawable/face14</item>
<item>@drawable/face15</item>
<item>@drawable/face16</item>
<item>@drawable/face17</item>
<item>@drawable/face18</item>
<item>@drawable/face19</item>
<item>@drawable/face20</item>
<item>@drawable/face21</item>
<item>@drawable/face22</item>
<item>@drawable/face23</item>
<item>@drawable/face24</item>
<item>@drawable/face25</item>
<item>@drawable/face26</item>
<item>@drawable/face27</item>
<item>@drawable/face28</item>
<item>@drawable/face29</item>
<item>@drawable/face30</item>
<item>@drawable/face31</item>
<item>@drawable/face32</item>
<item>@drawable/face33</item>
<item>@drawable/face34</item>
</array>
</resources>
三、於.java檔中取用, 例如extends BaseAdapter的類別中
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView imageView;
if (convertView == null)
{
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(110, 110));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
}
else
{
imageView = (ImageView) convertView;
}
TypedArray typedArray = mContext.getResources().obtainTypedArray(R.array.res_mood_image);
imageView.setImageResource(typedArray.getResourceId(position, 0));
return imageView;
}
沒有留言:
張貼留言