簡體   English   中英

創建recyclerview時如何解決這個問題?

[英]How can I solve this problem while creating recyclerview?

我正在嘗試使用GridLayout創建Recyclerview + Cardview ,但 Android Studio 向我顯示錯誤,我需要知道這里出了什么問題一張顯示錯誤的圖片,代碼:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="120dp"
android:layout_height="190dp"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:layout_margin="5dp"
cardview:cardcornerRadius="4dp">
<LinearLayout
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
<ImageView
  android:id="@+id/book_img_id"
  android:layout_width="match_parent"
  android:layout_height="160dp"
  android:scaleType="centerCrop"
  android:background="#2d2d2d"/>
<TextView
  android:id="@+id/book_title_id"
  android:textColor="#2d2d2d"
  android:textSize="13sp"
  android:gravity="center"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:text="سكر"/>
</LinearLayout>
</androidx.cardview.widget.CardView>

使用app:cardCornerRadius="4dp"而不是cardview:cardCornerRadius="4dp"

cardCornerRadius屬性在 app 下

嘗試如下代碼:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="120dp"
    android:layout_height="190dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardCornerRadius="4dp">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:src="@mipmap/ic_launcher_round"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Android"/>
    </LinearLayout>
</androidx.cardview.widget.CardView>

我希望它能幫助你

暫無
暫無

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

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