0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AndroidStudio activity_main の基本的なもの

Last updated at Posted at 2024-12-05

はじめに

こちらの記事は初心者向けとなります。
自己満足と備忘録として作らせていただいてます。

おまじない

最初に作ったタグの中に下記の記載をする
xmlns:android="http://schemas.android.com/apk/res/android"

LinearLayoutが最初にあるなら

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    あとの何らかの処理
>


各種タグ <> 要更新

レイアウト部品(ビューグループ)

開始タグ<>と終了タグ</>が必要になる
このタグで囲んだ画面部品をまとめる
結構使うから覚えておくと良い

タグ 機能
LinearLayout ビューをまとめたり
書き方 ※タグをLinearLayoutとした場合
<LinearLayout//開始タグ
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
> //開始タグ
    画面部品...
    画面部品...
</LinearLayout> //終了タグ

開始タグである
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"①
android:layout_height="match_parent"②
>
これの①、②でレイアウト枠の設定とかを行っていて
レイアウトの枠が画面いっぱいに広がってますということになる


画面部品(ビュー、ウィジェット)

表以外にもたくさんある
さまざまな機能を持った部品たち
最初はレイアウト部品と組み合わせてパーフェクトな配置を目指す

タグ 機能
TextView 文字  
EditText テキストボックス
Button ボタン
RadioButton ラジオボタン
CheckBox チェックボックス
Spinner ドロップダウンリスト
ListView リスト表
SeekBar スライダー(スクロールできるやつ)
書き方 ※タグをTextViewとした場合
<TextView
この中に属性
/>

記載する属性 要更新

だいたいはandroid:~ていうのを使う
andまで打てば候補を出してくれるのでお目当ての属性を探す
下記はその例

  • android:id="@+id/名前"
    ・文字の変更など、いじる必要があるタグ内に記載
    ・名前は他の部品と重複させないこと
    ・行うアクションなどを名前に記載し、分かりやすくすると良い

  • android:id="表示させたい文字"
    ・テキストビューやボタンに表示される文字

配置する部品の大きさやレイアウト調整

  • android:layout_width = "属性値"
    ・横幅の大きさ※属性値参照
  • android:layout_height = "属性値"
    ・縦幅の大きさ※属性値参照
属性値 内容
数値dp その数値の大きさになる
warp_content サイズが必要に応じて自動調整される
match_parent 親となる部品のサイズいっぱいに調整される
大きさの設定例
android:layout_width = "match_parent"
android:layout_height = "warp_content"


  • android:layout_margin① = "属性値"
    ①で方向を指定し、その方向の自部品の外側に余白を作る
    ①に入る値
     上:Top
     下:Bottom
     左:Start
     右:End
    "属性値"には数値dpを入れることでその数値分の余白が作られる
下方向に8dpの余白をつくる
 android:layout_marginBottom = "8dp"

空白のイメージ例
  □<設定した四角の物体
  8dpの空白
  ↓
  □


  • android:layout_padding① = "属性値"
     こちらはmarginとは違い内側に空白を作る
     ①と"属性値"入る値はmarginと同じ
右方向に余白を作る
android:layout_paddingEnd = "50dp"
空白のイメージ例 ↓
テキスト<----50dp---->
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?