Linked Questions

Popular Questions

FrameLayout height not matching parent

Asked by At

I have the following layout as custom view in AlertDialog.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:layout_gravity="center"
    android:gravity="center"
    android:padding="16dp">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="vertical">

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:columnCount="3">

            <TextView
                android:id="@+id/code1"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:gravity="center"
                android:text="\u2022"
                android:textSize="@dimen/match_code_digit_size"
                tools:ignore="HardcodedText" />

            <TextView
                android:id="@+id/code2"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:layout_marginBottom="20dp"
                android:gravity="center"
                android:text="\u2022"
                android:textSize="@dimen/match_code_digit_size"
                tools:ignore="HardcodedText" />

            <TextView
                android:id="@+id/code3"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:gravity="center"
                android:text="\u2022"
                android:textSize="@dimen/match_code_digit_size"
                tools:ignore="HardcodedText" />

            <Button
                android:id="@+id/k1"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:text="1"
                android:textSize="@dimen/match_code_button_text"
                tools:ignore="HardcodedText" />

            <Button
                android:id="@+id/k2"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:text="2"
                android:textSize="@dimen/match_code_button_text"
                tools:ignore="HardcodedText" />

            <Button
                android:id="@+id/k3"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:text="3"
                android:textSize="@dimen/match_code_button_text"
                tools:ignore="HardcodedText" />

            <Button
                android:id="@+id/k4"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:text="4"
                android:textSize="@dimen/match_code_button_text"
                tools:ignore="HardcodedText" />

            <Button
                android:id="@+id/k5"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:text="5"
                android:textSize="@dimen/match_code_button_text"
                tools:ignore="HardcodedText" />

            <Button
                android:id="@+id/k6"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:text="6"
                android:textSize="@dimen/match_code_button_text"
                tools:ignore="HardcodedText" />

            <Button
                android:id="@+id/k7"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:text="7"
                android:textSize="@dimen/match_code_button_text"
                tools:ignore="HardcodedText" />

            <Button
                android:id="@+id/k8"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:text="8"
                android:textSize="@dimen/match_code_button_text"
                tools:ignore="HardcodedText" />

            <Button
                android:id="@+id/k9"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:text="9"
                android:textSize="@dimen/match_code_button_text"
                tools:ignore="HardcodedText" />

            <Button
                android:id="@+id/k0"
                android:layout_width="@dimen/match_code_button_size"
                android:layout_height="@dimen/match_code_button_size"
                android:layout_column="1"
                android:text="0"
                android:textSize="@dimen/match_code_button_text"
                tools:ignore="HardcodedText" />

        </GridLayout>

        <TextView
            android:id="@+id/error"
            style="@style/ErrorText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="@string/match_error"
            android:visibility="invisible" />

    </LinearLayout>

    <FrameLayout
        android:id="@+id/progress"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#80ffffff"
        android:visibility="visible">

        <ProgressBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />

    </FrameLayout>

</FrameLayout>

Sorry for large volume of layout, put it here 'as is'.

Pay attention to the bottom FrameLayout with id progress. Despite it has android:layout_height="match_parent", on the device it looks like "wrap_content" - has height only matching inner ProgressBar. Though in Android Studio designer shown perfectly, occupying whole the view.

What's wrong?

Here is how layout looks in AS designer

AS designer

and on the device (tried both emulator and real device, the same effect)

Device

Related Questions