Cardview在Android Studio 3.5.1中不显示 [英] Cardview not displaying in android studio 3.5.1

查看:106
本文介绍了Cardview在Android Studio 3.5.1中不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在较旧的android studio版本3.3.1上尝试过CardView库,并且代码正在工作.模拟器显示正确的图像.但是,我切换到新版本3.5,CardView中什至没有显示,甚至没有TextView.

I have tried CardView library on the older android studio version 3.3.1 and the code was working. The emulator was displaying the correct images. But, I switched to the new version 3.5 nothing is displaying in the CardView, not even a TextView.

xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp"
    android:background="#fcfcfc"
    android:gravity="center"
    android:id="@+id/LinearLayout1">

    <!-- A CardView that contains a TextView -->
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="200dp"
        card_view:cardCornerRadius="4dp">

        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v7.widget.CardView>

</LinearLayout>

等级:

dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.android.support:cardview-v7:28.0.0'

}

推荐答案

您应该使用

<androidx.cardview.widget.CardView //XML Section

添加 AndroidX 依赖项

implementation 'androidx.cardview:cardview:1.0.0'

这篇关于Cardview在Android Studio 3.5.1中不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆