Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 1 year has passed since last update.

レイアウトデザインで少し便利「GuidLine」

Last updated at Posted at 2024-01-08

レイアウトデザインで少し便利「GuidLine」

constraintlayout内では、View同士やlayoutViewに対して制約をつけることで
相対的に位置を指定することができます。
「GuidLine」を使用することでconstraintlayout内で柔軟なレイアウトを作成することができます。

▼使い方

前提
Guideline自体は、あくまでも目印となるViewであり、実際にUIでは表示されません。
Android StudioのDesignでは点線で表示されます。

属性の指定

Guidelineの属性を指定する必要があります。
「orientation」「layout_constraintGuide_percent」

<androidx.constraintlayout.widget.Guideline
    android:id="@+id/guideline"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintGuide_percent="0.5" />
- orientation

値を設定することで、Guidelineの方向を指定することができます。
・orientation="horizontal"と指定した場合
スクリーンショット (4).png
・orientation="vertical"と指定した場合
スクリーンショット (5).png

- layout_constraintGuide_percent

値を設定することで、Guidelineの相対的な位置を指定することができます。
以下の画像は、orientation="horizontal"と指定していた時の例です。

・layout_constraintGuide_percent="0.5"と指定した場合
スクリーンショット (4).png
・layout_constraintGuide_percent="0.1"と指定した場合
スクリーンショット (8).png

▼使用例

以下の例は、constraintlayout内で下部10%の位置で固定でバナーを表示させた時です。
スクリーンショット (7).png

最後に

制約をつけるのが難しい時に便利!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?