Search code examples
androidemulationpreview

Android Emulator Not Displaying The App Correctly (Android Studio)


I'm making a basic phrases app (I've mentioned this in my previous question), and I got everything down. However, the emulator isn't displaying the app correctly at all. This is the preview within the studio:

enter image description here

And this is what the emulator displays:

enter image description here

There aren't any errors within my code, and all Android Studio components are up-to-date. What's going on? This is my XML:

<?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_row="0"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:layout_gravity="fill"
        android:text="Hello"
        android:onClick="buttonTapped"
        android:id="@+id/button" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_row="0"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:layout_gravity="fill"
        android:text="How are you?"
        android:onClick="buttonTapped"
        android:id="@+id/howareyou" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_row="1"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:layout_gravity="fill"
        android:text="Good Evening"
        android:onClick="buttonTapped"
        android:id="@+id/goodevening" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_row="1"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:layout_gravity="fill"
        android:text="Please"
        android:onClick="buttonTapped"
        android:id="@+id/please" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_row="2"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:layout_gravity="fill"
        android:text="My name is..."
        android:onClick="buttonTapped"
        android:id="@+id/mynameis" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_row="2"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:layout_gravity="fill"
        android:text="Do you &#10; speak English?"
        android:onClick="buttonTapped"
        android:id="@+id/doyouspeakenglish" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="0"
        android:layout_row="3"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:layout_gravity="fill"
        android:text="Welcome"
        android:onClick="buttonTapped"
        android:id="@+id/welcome" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_row="3"
        android:layout_columnWeight="1"
        android:layout_rowWeight="1"
        android:layout_gravity="fill"
        android:text="I live in..."
        android:onClick="buttonTapped"
        android:id="@+id/ilivein" />

</GridLayout>

Solution

  • When the layout gravity is set to fill, it fills its container. That's why it displays only the first button.

    Maybe the current emulator has some problems to render the gridlayout so the root layout became the container of the button.

    I tried your xml file and it works perfectly on both emulated and real devices.