joel
joel

Reputation: 43

GridLayout not displaying

GridLayout inside a LinearLayout not showing at all and am not sure why. trying to make a simple calculator but i can't get the buttons to display.

changed height, width background color but not sure why is not displaying.

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="horizontal"
>

<TextView
    android:id="@+id/main_display"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="123456789"
    android:gravity="end"

    android:background="@color/mainDisplay" />

<GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:columnCount="4"
        android:rowCount="5"
        >
        <Button
         android:id="@+id/bc"
            android:text="@string/bc"

            />
        <Button
            android:id="@+id/bparentesis"
            android:text="@string/bparentesis"
            />

        <Button
            android:id="@+id/b7"
            android:text="@string/b7"
            />
        <Button
            android:id="@+id/b8"
            android:text="@string/b8"
            />
        <Button
            android:id="@+id/b9"
            android:text="@string/b9"
            />
        <Button
            android:id="@+id/bmulti"
            android:text="@string/bmulti"
            />
        <Button
            android:id="@+id/b4"
            android:text="@string/b4"
            />

    </GridLayout>

i trying to make a 4x5 grid of buttons for a calculator

Upvotes: 1

Views: 59

Answers (2)

milad salimi
milad salimi

Reputation: 1660

I think you should use this :

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

And I think for calculator if you use horizontal linearlayout instead of gridlayout its better too.

in the other hands for per row use horizontal linearlayout.

Upvotes: 1

End User
End User

Reputation: 812

TextView's width is match_parent change it to wrap_content it will work and show your GridLayout or chanage your orientation of LinearLayout to vertical

Upvotes: 1

Related Questions