# /res/values 目录详解
------
**/res/values** 下可以放置的文件有:
> * strings.xml > * arrays.xml > * dimens.xml > * colors.xml > * styles.xml
### 绘制表格
| 文件类型 |作用|temp| | -------- | -----: | :----: | | strings.xml | $1600 | | | arrays.xml | $12 | | | dimens.xml | $1 | |
------
## strings.xml
**详解**利用`arrays.xml`文件存放数组,并读取的*过程*。
### 示例代码1
```java int[] resIds = new int[] { R.array.proto, R.array.zerg, R.array.terran }; String[] armType = new String[] { "神族兵种:", "虫族兵种:", "人族兵种:" }; getArms(resIds, armType); ``` ```java private void getArms(int[] ids, String[] typeNames) { int len1 = ids.length; String[][] arms = new String[len1][];
for (int i = 0; i < len1; i++) { String[] armsType = this.getResources().getStringArray(ids[i]); int len = armsType.length; arms[i] = new String[len]; System.out.println(typeNames[i]); for (int j = 0; j < len; j++) { arms[i][j] = armsType[j]; System.out.print(arms[i][j] + " "); } System.out.println(); } } ``` ### 示例代码2
```java int[] resIds = new int[] { R.array.proto, R.array.zerg, R.array.terran }; String[] armType = new String[] { "神族兵种:", "虫族兵种:", "人族兵种:" }; getArms(resIds, armType); ``` ```java private void getPlanets(String[] typeNames) { String[] ids = this.getResources().getStringArray(R.array.planet); int len1 = ids.length; String[][] planets = new String[len1][]; for (int i = 0; i < len1; i++) { String[] planetArr = ids[i].split(","); int len2 = planetArr.length; planets[i] = new String[len2]; System.out.println(typeNames[i]); for (int j = 0; j < len2; j++) { planets[i][j] = planetArr[j]; System.out.print(planetArr[j]+" "); } System.out.println(); } } ``` ### 示例代码3
```java String[] province = new String[] { "广东:", "北京:", "云南:" }; getCities(province); ``` ```java private void getCities(String[] names) { TypedArray typedArray = getResources().obtainTypedArray(R.array.china); int len1 = typedArray.length(); String[][] cities = new String[len1][]; for (int i = 0; i < len1; i++) { int resArrID = typedArray.getResourceId(i, 0); String[] cityArr = this.getResources().getStringArray(resArrID); int len2 = cityArr.length; cities[i] = new String[len2]; System.out.println(names[i]); for (int j = 0; j < len2; j++) { cities[i][j] = cityArr[j]; System.out.print(cityArr[j]+" "); } System.out.println(); } } ```
---
---
感谢阅读!
作者 [@莫黎笙][本文地址][^code] 2015 年 01月 19日
[^code]: 本文地址,转载请保留原作者与地址。
[1]: http://www.cnblogs.com/mulisheng/p/4234870.html