<GridLayout Redlined in Android Studio-How to fix

38 views Asked by At

I'm new here so I'm not sure about the depth of this question being appropriate, but I've been working on this Project for weeks and I've got an error I don't know how to fix.

enter image description here

The layout is a Grid. The Gridlayout in the html file is printed in red type in the file: activity_main_menu.xml, which is one of several in my program. Obviously, it's not supposed to be red..... That's why I'm writing.... I don't know what to do! The Gridlayout at the end of the file is underscored red also.

I have three other xml files, and 4 java files that I am working on for this project in Android Studio. (I did have Gradle errors (3-4?), but they have disappeared?)

I could use some help/suggestions on this....I'll attach a pic of the project, and the code of the file below.

Thank You! B."Lee" Ecke

file: activiy_main_menu.xml trouble redlined: GridLayout

The code ahead is correct and not flagging. I couldn't paste the whole file so here the part where the GridLayout is:

  1. <TextView
  2.    `android:id="@+id/lblWelcome"`
    
  3.    `style="@style/TextView"`
       `android:layout_width="wrap_content"`
       `android:layout_height="wrap_content"`
       `android:gravity="center_horizontal"`
       `android:text="@string/Welcome"`
       `android:textAppearance="?android:attr/textAppearanceLarge"`
       `android:layout_marginTop="24sp" />`
    
    <GridLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_centerHorizontal="true"
       android:layout_centerVertical="true"
       android:columnCount="3"
       android:orientation="horizontal"
       android:rowCount="2"
       android:useDefaultMargins="true">
    
       <Button
           android:id="@+id/btnWeather"
           android:layout_width="100dp"
           android:layout_height="wrap_content"
           android:layout_row="0"
           android:layout_column="0"
           android:layout_gravity="center|fill"
           android:text="@string/goWeather"
           android:textColor="@color/material_dynamic_primary80" />`
    

I have looked at other files for linking terms, checked my Component Tree for errors and found none. My buttons are all where they should be which is odd, given the red text of the Gridlayout. I don't know when it turned red. I've tried to think outside the box, but I don't know what to check next.

1

There are 1 answers

0
C.F.G On

You should close the GridLayout environment using <GridLayout/>.

You can also use androidx.gridlayout as follow:

add implementation 'androidx.gridlayout:gridlayou:last_version to your dependencies then click on sync now then use

<androidx.gridlayout.widget.GridLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

<Button
       android:id="@+id/btnWeather"
       android:layout_width="100dp"
       android:layout_height="wrap_content"
       android:layout_row="0"
       android:layout_column="0"
       android:text="@string/goWeather"
       android:textColor="@color/material_dynamic_primary80" />

<androidx.gridlayout.widget.GridLayout/>