Entoverse

Reactのこと

Android Studio 画面デザイン ボタンを追加する

Android Studioで「New Project」の「Basic Activity」を選択すると

新規プロジェクトが作成されます。

Basic Activity

New Project Basic Activity

コード変更せず、 実行すると

デバッグ実行ボタン

デバッグ実行ボタン

[TextView]・[Next Button]が配置された[First Fragment]画面が立ち上がります。

[Next]ボタンをタップすると、もう1つの[Second Fragment]画面に切り替わります。

Emulator Debug実行

Emulator Debug実行

この2つの画面レイアウトは、 プロジェクト内の[res→layout]フォルダに入っています。

res→layoutフォルダ

res→layoutフォルダ

「fragment_first.xml」が最初に実行されるViewです。

XMLの中を見ると、 <Button />と<TextView />が入っていて、

ボタンには、 layout_constraintTop_toBottomOf=textview_firstになっていて

テキストには、 layout_constraintBottom_toTopOf=button_firstです。

View Layout画面

View Layout画面

上のテキストと下のボタンは、 部品同士をlayout_constraint○○○_to○○○Ofで関係性を作っているようでした。

ボタンを一個追加したい場合は下記のようにすれば良い

<Button
	android:id="@+id/button1"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:text="新しいボタン"
	app:layout_constraintBottom_toBottomOf="parent"
	app:layout_constraintEnd_toEndOf="parent"
	app:layout_constraintStart_toStartOf="parent"
	app:layout_constraintTop_toBottomOf="@+id/button_first" />

layout_constraintTop_toBottomOf=button_firstを指定することで、

[NEXT]ボタンの下に配置されます。

[NEXT]ボタン側は、layout_constraintBottom_toBottomOf="parent"を削除し、

layout_constraintBottom_toTopOf="@id/button1"を追加

View Layout ボタン追加

View Layout ボタン追加

[新しいボタン]という名前のButton が追加できた。

 

Android Studio ボタンクリック イベント作成 | 超獣農場

 

mjeld.com