繁体   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