繁体   English   中英

Android开发。 卡片视图不工作?

[英]Android development. CardView not working?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:background="#F3F3F3F3"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/dersName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"/>

    </android.support.v7.widget.CardView>

</LinearLayout>

不幸的是,ProjectTry 已停止

我也添加了这段代码

implementation 'com.android.support:recyclerview-v7:28.0.0'
//noinspection GradleCompatible
implementation 'com.android.support:cardview-v7:28.0.0'

编译成功,但它给了我不幸的是 ProjectTry 已停止我该如何克服这个问题? 当我输入

将我的库更新到 androidX 后我遇到了同样的问题

implementation 'androidx.cardview:cardview:1.0.0'

为了克服这个问题。

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
    android:id="@+id/dersName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginRight="10dp"/>
</androidx.cardview.widget.CardView>

使用此代码

   <androidx.cardview.widget.CardView 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        app:elevation="5dp">
    </androidx.cardview.widget.CardView>

如果您的清单文件有 android:hardwareAccelerated="false" 行,请将其删除。

详见https://developer.android.com/guide/topics/graphics/hardware-accel.html?hl=ru

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM