簡體   English   中英

在 Gridlayout 中的 MaterialCardView 中找不到屬性 layout_columnWeight

[英]Attribute layout_columnWeight not found in MaterialCardView inside Gridlayout

我正在使用 Gradle 中實現的最新網格布局,如下所示:


implementation 'com.google.android.material:material:1.3.0'

下面是我在 GridLayout 中的 MaterialCardView


 <GridLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="3"
            android:columnCount="2"
            android:rowCount="2">

            <com.google.android.material.card.MaterialCardView
                android:id="@+id/mcv_card_1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:focusable="true"
                android:theme="@style/MaterialTheme"
                app:cardCornerRadius="5dp"
                app:cardElevation="1dp"
                app:cardUseCompatPadding="true"
                app:contentPadding="10dp"
                app:strokeWidth="1dp"
                app:rippleColor="@color/secondaryRippleColor5"
                app:layout_columnWeight="1"
                app:layout_rowWeight="1">

            </com.google.android.material.card.MaterialCardView>
            
        </GridLayout>

我收到以下錯誤


AAPT: error: attribute layout_columnWeight (aka myapps.ke.playapp:layout_columnWeight) not found.
AAPT: error: attribute layout_layout_rowWeight (aka myapps.ke.playapp:layout_rowWeight) not found.

我已經嘗試將 app:layout_columnWeight 更改為 android:layout_columnWeight 並且工作正常但它不向后兼容並且僅支持 Api Level 21 及以上

您需要將 androidx GridLayout添加到您的依賴項中:

implementation "androidx.gridlayout:gridlayout:1.0.0"

然后在您的 XML 中使用:

<androidx.gridlayout.widget.GridLayout
  ....>

</androidx.gridlayout.widget.GridLayout>

而不是框架一

layout_columnWeight是 android 標准庫的一部分,所以你需要將app:layout_columnWeight改為android:layout_columnWeight

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM