LoginSignup
11
13

More than 5 years have passed since last update.

Androidのxmlレイアウトで画面めいっぱいに表示する方法

Posted at

AndroidStudioのxmlレイアウトエディタでGUIを使ってレイアウトを作っていると、妙な余白が常に付きます。
この余白、てっきりRelativeLayoutの仕様かと思ってたのですが、そんなことなかったです。
xmlをよく読めば明白でした


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:paddingLeft="0dp">

        <WebView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/webView"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
    </LinearLayout>
</RelativeLayout>

    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"

これ。
@dimenで定義された定数値によるpaddingが親切に自動的に挿入されていました。
この4行をRelativeLayoutから消せばぴったし画面の余白を付けずに表示することが出来ました。

11
13
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
11
13