Search code examples
javaandroidandroid-studiogrid-layout

Can't see button inside GridLayout


In Android Studio. Was following a youtube tutorial about GridLayout. Trying to use GridLayout with layout_width and height that set to wrap_content and add a button to it. But I can't see the button, or anything else I add normally.

Any idea how to fix this?

Picture:

I was trying to follow this video

He can see all of the button + text, I cant

XML Text code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity">

<android.support.v7.widget.GridLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="8dp">

    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp" />
</android.support.v7.widget.GridLayout>

</android.support.constraint.ConstraintLayout>

Java code (Don't think needed):

package com.example.naveh.layla;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    }
}

Solution

  • From Github link : https://github.com/buckyroberts/Source-Code-from-Tutorials/tree/master/Android_Beginners/017%20GridLayout

    Use GridLayout instead of android.support.v7.widget.GridLayout