社内se × プログラマ × ビッグデータ

プログラミングなどITに興味があります。

Android(kotlin) 初めての画面作成

この記事は、Kotlin で Android アプリ開発 内の一つの記事です。
Android アプリ開発の画面作成を学ぶために、取りあえずプロジェクトを作成してみます。

プロジェクトの作成

Empty Activity を選んでいきます。

f:id:blueskyarea:20200404193336p:plain
empty_activity

プロジェクト名などは適当に設定します。
自分は "View Practice" と設定しています。

strings.xml に文字列情報を追加する

res/values/strings.xml
画面に表示する文字列を設定するために以下のように記述します。

<resources>
    <string name="app_name">View Practice</string>
    <string name="in_msg">Input your name</string>
</resources>

レイアウトファイルの編集

res/layout/activity_main.xml
初期では ConstraintLayout が設定されていますが、分かり易い LinearLayout で書き直しします。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/inLabelInput"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="5dp"
        android:background="#ffffff"
        android:text="@string/in_msg"
        android:textSize="25sp"/>
</LinearLayout>

エミュレータでアプリを実行する

以下のような画面がエミュレータ上で作成されます。

f:id:blueskyarea:20200404233245p:plain
first-view

とりあえず、画面作成が出来ました。
次回は画面にある各部品について学んでいきます。