【问题标题】:Recycleview of cardview is not working.How can I fix it?cardview的recycleview不起作用。我该如何解决?
【发布时间】:2020-12-27 22:45:32
【问题描述】:

我是一个尝试学习android开发的初学者。我尝试使用下面的cardview制作recyclerview。但是当我尝试运行它不起作用。那么,我该如何解决它? 卡片查看代码如下:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:cardCornerRadius="10dp"
    android:id="@+id/list_layout"
    android:background="@color/white"
    android:layout_marginBottom="10dp"
    >
    <LinearLayout
        android:layout_width="2000dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >
  <RadioButton
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/ratio_button"
      />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Do the work"
            android:textSize="20sp"
            android:id="@+id/task"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/delete"
            android:backgroundTint="@color/red"
            android:text="Delete"
            android:visibility="invisible"
            />
    </LinearLayout>

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

【问题讨论】:

  • 不工作是什么意思?请提供您所面临问题的更多详细信息。
  • 投了反对票,因为没有提供关于什么不起作用的详细信息?
  • Tru useCompactPadding= true 在材料卡视图中。或者如果不起作用,请提供 ui 的屏幕截图,以便我们帮助您解决问题
  • 请详细说明!!

标签: android android-studio android-layout android-recyclerview


【解决方案1】:

implementation 'com.android.support:cardview-v7:28.0.0' 之后,让我们试试这个:

androidx.cardview.widget.CardView

【讨论】:

    【解决方案2】:

    你的问题不清楚!但是在尝试了您的 XML 文件之后,我相信您在应用级 Gradle 文件中缺少材料依赖项

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

    MaterialCardView 是该库的一部分,您应该在使用它之前将其包含在应用的依赖项中。

    【讨论】:

      猜你喜欢
      • 2019-12-26
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 2020-09-03
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 2017-01-10
      相关资源
      最近更新 更多