LinearLayout doesn't fill the parent

Alexander Goncharenko picture Alexander Goncharenko · Aug 12, 2014 · Viewed 8.7k times · Source

LinearLayout doesn't fill the parent. I need to fill all elements by width.

Here is a photo that is showing on the smartphone. But in Android Studio xml preview all is looking right.

photo

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/bg_color"
    android:orientation="vertical">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textMultiLine"
        android:ems="10"
        android:id="@+id/editText3"
        android:hint="Сообщение" />

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/editText2"
        android:hint="Тема" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="дата"
            android:id="@+id/textView"
            android:layout_weight="1" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="время"
            android:id="@+id/textView2"
            android:layout_weight="1" />
    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Важность"
        android:id="@+id/textView3" />

    <SeekBar
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/seekBar"
        android:layout_gravity="center_horizontal" />

</LinearLayout>

Answer

0101100101 picture 0101100101 · Aug 12, 2014

Replace fill_parent with match_parent everywhere. Beside that, you have to set match_parent for the fragment's container layout inside your activity's XML.