<GridLayout Redlined in Android Studio-How to fix

问题描述 投票:0回答:1

enter image description here我是新来的,所以我不确定这个问题的深度是否合适,但我已经在这个项目上工作了几周,我遇到了一个错误,我不知道如何修复.

布局是一个网格。 html文件中的Gridlayout在文件:activity_main_menu.xml中以红色字体打印,这是我的程序中的几个之一。显然,它不应该是红色的......这就是我写的原因......我不知道该怎么办!文件末尾的 Gridlayout 也带有红色下划线。

我还有另外三个 xml 文件和 4 个 java 文件,我正在为这个项目处理

Android Studio
。 (我确实有 Gradle 错误(3-4?),但它们消失了?)

我可以对此使用一些帮助/建议......我将附上该项目的图片以及下面文件的代码。

谢谢你! B.“李”埃克

文件:activiy_main_menu.xml 麻烦红线:
GridLayout

前面的代码是正确的并且没有标记。我无法粘贴整个文件,所以这里是

GridLayout
的部分:

  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" />`
    

我查看了其他文件的链接术语,检查了我的组件树是否有错误,但没有发现任何错误。我的按钮都在它们应该在的位置,这很奇怪,因为

Gridlayout
的红色文本。不知道什么时候变红了。我尝试跳出框框思考,但我不知道接下来要检查什么。

java android html grid-layout
1个回答
0
投票

使用

androidx.gridlayout
如下:

implementation 'androidx.gridlayout:gridlayou:last_version
添加到您的依赖项中,然后单击
sync now
然后使用

<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/>
© www.soinside.com 2019 - 2024. All rights reserved.