![](/img/trans.png)
[英]No resource identifier found for attribute 'layout_columnWeight' in package 'android'
[英]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.