このフォルダは各種リソースファイルを配置するフォルダです。
リソースファイルとは画像ファイル、音楽ファイル、xmlファイル等です。
- drawableフォルダ
- layoutフォルダ
アイコン等の画像バイナリファイルを格納するフォルダです。
画像の大きさによりフォルダが分かれます。
| 項目名 | アイコン | 解像度 |
|---|---|---|
| drawable-ldpi | 36px | 120dpi |
| drawable-mdpi | 48px | 160dpi |
| drawable-hdpi | 72px | 240dpi |
| drawable-xhdpi | 96px | 320dpi |
| drawable-xxhdpi | 148px | 480dpi |
画面レイアウトを定義するxmlファイルが格納するフォルダです。
新しい画面レイアウトファイルを作成した場合、こちらに配置します。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
メニューボタンをクリックしたときに表示されるメニューを定義するxmlファイルを格納するフォルダです。
オプションメニューの項目は、javaプログラム内にも記述することが可能ですが、ローカライズの可能性を考慮すると、こちらに記述する方が適切でしょう。
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>
文字列等を定義するxmlファイルを格納するフォルダです。
- dimens.xml
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
画面に表示させる文字列は、ここにまとめて記述することが適切と言われています。
それはメンテナンス性やローカライズ性を考慮するべきだからです。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">HelloWorld</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
</resources>
アプリのスタイルに関する設定をここでまとめて管理できます。
例えば、viewの高さや幅、テキストのフォントやサイズなどです。
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
Androidアプリケーション全体の設計図に相当するxmlファイルです。
アプリケーション名やSDKバージョン、機能使用宣言、SDKバージョン、各種javaファイル名などの情報が書かれています。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.helloworld.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
だいたい把握できましたでしょうか?
どこになにがあるのか、ということが理解できると、なにをするにはどこを修正・追加するのかがわかるようになります。
しっかりと確認しておきましょう。