Android Studioにおけるレイアウトコードの記述方法

Android Studioでは、レイアウトコードをXML言語で記述できます。例として、以下の基本的なレイアウトコードを示します。

<?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:orientation="vertical">
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, Android Studio!" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
</LinearLayout>

上のコードでは、ルートビューコンテナとしてLinearLayoutを利用し、その横幅と高さをmatch_parent(つまり画面全体を満たす)に設定しています。そして、その中にTextViewとButtonを追加しました。TextViewは文字の内容を表示し、Buttonはクリックイベントに対応します。各ビューコンポーネントにはID、横幅、高さ、文字列などの独自の属性が設定されています。必要に応じて、さらにビューコンポーネントや属性をコードに追加することができます。

bannerAds