どうも、tatsuです!
今回から、今までの知識を使って簡単なメモ帳アプリを作っていこうと思います。
わからない箇所は他の記事を参考にしてみてください。
※この記事で使用しているAndroid Studioのバージョンは3.1.4です。
※この記事はメインプログラム言語としてKotlinを採用しています。
Javaは以下の記事をご覧ください。
作成手順
メモ帳アプリを作る上で必要な手順を以下にまとめました。
本記事では①と②を紹介します。
- 新しくプロジェクトを作る
- 画面レイアウトを作る
- 画面に動きをつける
- データベースに保存する
- テスト&手直し
- 完成物披露
①新しくプロジェクトを作る
それではメモ帳アプリ用のプロジェクトを作っていきます。
1. Android Studioを起動し、「Start a new Android Studio project」をクリックします。
2. 必要な項目を入力し、「Next」をクリックします。
今回は「SimpleMemo」というアプリ名にしました。
※「Include Kotlin Support」にチェックが入っていることを確認してください。
3. 何も変更せずに「Next」をクリックします。
4. 「Empty Activity」を選択し、「Next」をクリックします。
5. 必要な項目を入力し、「Finish」をクリックします。
今回は、作成したメモ一覧をメイン画面にしたいので「ListActivity」ktファイルと「activity_list」xmlファイルにしました。
6 .すると以下のような画面が立ち上がります。
これでプロジェクトの作成は完了です。
②画面レイアウトを作る
それではまず、画面のレイアウトを作っていきましょう。
本アプリは以下のレイアウトを使用します。
- activity_list.xml ・・・ 作成したメモを一覧で表示する画面のレイアウト
- activity_create_memo.xml ・・・ メモを作成する画面のレイアウト
activity_list.xml
activity_list.xmlは以下のようにします。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.android.tatsu.simplememo.ListActivity"> <ListView android:id="@+id/memoList" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="9"/> <Button android:id="@+id/newButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="新規作成する" /> </LinearLayout>
activity_create_memo.xml
次にactivity_create_memo.xmlを作ります。
1. ListActivityが格納されているフォルダを右クリックし、[New]→[Activity]→[Empty Activity]を選択します。
2. 必要な項目を入力し、「Finish」をクリックします。
「CreateMemoActivity」ktファイルと「activity_create_memo」xmlファイルにしました。
activity_create_memo.xmlは以下のようにします。
入力可能フィールドが1つとボタン2つだけのシンプルな画面にしてみました。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.android.tatsu.simplememo.CreateMemoActivity"> <EditText android:id="@+id/body" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20sp" android:inputType="textMultiLine" android:lines="50" android:layout_weight="9" android:gravity="top|left" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_weight="1"> <Button android:id="@+id/register" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="登録する" /> <Button android:id="@+id/back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="戻る" /> </LinearLayout> </LinearLayout>
まとめ
今回は「①新しくプロジェクトを作る」と「②画面レイアウトを作る」を紹介しました!
続きは次回にしていきます。
コメントを残す