JavaScriptを有効にしてください

KotlinでAndroidアプリ開発(todoList) その3:レイアウトを作る

 ·  ☕ 2 分で読めます  ·  ✍️ saiki

さて、やっとAndroidアプリ開発っぽいところに入ります。

まずはxmlでレイアウト(画面に何がどう表示されるか)を設定します。

とりあえずサイドメニューは置いて置いて、メインのリストを作っていきます。

activity_main.xml

メインの画面のレイアウトを設定。

Constraint Layoutというのが新しくできたらしくデフォではそれになっていますがちょっと使い方がわからな過ぎたので今回は一旦LinearLayoutでさらっと。

画面いっぱいにListViewを置いただけです。

<?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"
    tools:context="net.rensyuu.mytodo.MainActivity">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

task_list_item.xml

タスクのリストに表示されるアイテムのレイアウト。

とりあえずチェックボックスを置いただけです。手抜きじゃ無いよ。

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

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="CheckBox" />


</LinearLayout>

 

簡単ですね。

次はmodelを作ります。

ではまた。

 

参考書籍:

1から勉強するのにおすすめでした。(プログラミング経験は無いときつそう)

共有

saiki
著者
saiki
Android App Developper