Skip to main content
  1. Posts/

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

·131 words·1 min
Saiki Iijima
Author
Saiki Iijima
Cozy life, fun tech
Table of Contents

さて、やっと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から勉強するのにおすすめでした。(プログラミング経験は無いときつそう)

Related

KotlinでAndroidアプリ開発(todoList) その2:画面を考える
·14 words·1 min
KotlinでAndroidアプリ開発(todoList) その1:計画とプロジェクト生成
·217 words·2 mins
Kotlin dataクラスとは何か?と使い方 便利!
·192 words·1 min