第3回PG初心者がAndroidStudioでアプリ開発してみた~Wedgetの配置ってどうやるの??②~

こんにちは!

最近メンバーに持ち上げてもらって調子に乗りそうな草もちです🤣

読者のみなさまの想像を壊さぬよう、一生顔出しはしないと心に誓いました🎅✨

 

さてさて、

AndroidStudioのレイアウトの続きを書いていきたいと思います。

前回はRelativeLayoutについて説明しました。

今回は

  • Linerlayout
  • Framelayout

について説明していきます!👨‍🍳

Linerlayout

Linerlayoutとは、並べることを目的としたレイアウトです。

android:orientation=“horizontal”を追加すると、

<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"
    android:orientation="horizontal"
    tools:context=".MainActivity">

水平にTextViewが並びました。

android:orientation=“vertical”を追加すると、

<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"
    android:orientation="vertical"
    tools:context=".MainActivity">

垂直方向に並びます。

 

Framelayout

Framelayoutはウィジェットを重ねて配置するためのレイアウトです。

書いた順に重ねられるので、一番最初に書いたものが一番下に配置されます。

具体例がこちら↓↓↓

<FrameLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="300dp"
        android:layout_height="300dp"
        app:srcCompat="@drawable/broccoli" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="200dp"
        android:layout_height="200dp"
        app:srcCompat="@drawable/strawberry" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="100dp"
        android:layout_height="100dp"
        app:srcCompat="@drawable/banana" />
</FrameLayout>

 

ちなみに画像の置く場所は、

画質荒くてすみません😥

app/res/drawable配下にコピペすればDesign画面のImageViewで使えます!

 

以上、AndroidStudioのレイアウトについてでした🎈✨

タイトルとURLをコピーしました