リソースファイルはプロジェクトのres/ディレクトリ以下の、定められた名前のディレクトリに配置する必要があります。この名前付け規則に違反した場合には「invalid resource directory name」エラーとなります。
| 種類 | リソース名 | 格納されるファイル | クラス | ディレクトリ |
|---|---|---|---|---|
| Animation | Tween animation | トゥイーン アニメーション | R.anim | anim/ |
| Frame animation | フレーム アニメーション | R.drawable | drawable/ | |
| Color | ColorStateList | 色リスト | R.color | color/ |
| Image | Drawable | 画像ファイル
|
R.drawable | drawable/ |
| Layout | Layout | UIのレイアウト ファイル | R.layout | layout/ |
| Menu | Menu | アプリケーションのメニュー | R.menu | menu/ |
| String | String | 文字列 | R.string | values/ |
| String Array | 文字列の配列 | R.array | ||
| Quantity Strings | 複数形の表現 | R.plurals | ||
| Style | Style | UI要素のスタイル | R.style | values/ |
| その他 | Bool | ブール値 | R.bool | values/ |
| Color | 色 | R.color | ||
| Dimension | 寸法 | R.dimen | ||
| ID | ID | R.id | ||
| Integer | 整数 | R.integer | ||
| Integer Array | 整数の配列 | R.array | ||
| Typed Array | リソースの配列 | |||
| 任意のファイル | R.raw | raw/ | ||
| 任意のXMLファイル | xml/ |
代替リソースのディレクトリは、次の定義規則に従う必要があります。
| 設定 | 修飾語 | 記述例 | 説明 |
|---|---|---|---|
| MCC and MNC |
|
The mobile country code (MCC), optionally followed by mobile network code (MNC) from the SIM card in the device. | |
| Language and region |
|
The language is defined by a two-letter ISO 639-1 language code, optionally followed by a two letter ISO 3166-1-alpha-2 region code (preceded by lowercase "r"). | |
| smallestWidth | sw<N>dp |
|
|
| Available width | w<N>dp |
|
|
| Available height | h<N>dp |
|
|
| Screen size |
|
||
| Screen aspect |
|
||
| Screen orientation |
|
||
| Dock mode |
|
||
| Night mode |
|
||
| Screen pixel density (dpi) |
|
||
| Touchscreen type |
|
||
| Keyboard availability |
|
||
| Primary text input method |
|
||
| Navigation key availability |
|
||
| Primary non-touch navigation method |
|
||
| Platform Version (API level) | v<N> |
|
メニューの【File → New → Other】を選択します。そして[Android]の[Android XML File]を選択し、[Next]をクリックします。

ここでは次のようなリソースを作成できます。

コンパイル時にはaapt (Android Asset Packaging Tool) により、R.javaファイルが自動で生成されます。このファイルには、リソースのIDが定義されます。Accessing Resources | Android Developers
外部から入手したプロジェクトには、このファイルがあらかじめ含まれていることがあります。その状態でEclipseにインポートすると、自動生成されたR.javaファイルと重複することになり「The type R is already defined」とエラーとなることがあります。そのような場合には、プロジェクトに含まれていたR.javaファイルを削除します。