代码之家  ›  专栏  ›  技术社区  ›  J. Doe

cardview colapsses my as app at runtime,如何正确使用cardview?

  •  0
  • J. Doe  · 技术社区  · 5 年前

    我有一个简单的应用程序在运行时崩溃。当我移除 CardView 查看应用程序是否正常运行。

    如何添加 卡片视图 适当地查看?

    我怀疑 卡片视图 视图应该不同,然后: android.support.v7.widget.CardView 是的。

    这是 activity.main.xml 以下内容:

    <?xml version="1.0" encoding="utf-8"?>
    
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    
        <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>
    

    这是 build.gradle (模块:应用程序):

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 29
        buildToolsVersion "29.0.2"
        defaultConfig {
            applicationId "android.example.blah1111"
            minSdkVersion 15
            targetSdkVersion 29
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    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:29.0.0'
    }
    
    1 回复  |  直到 5 年前
        1
  •  1
  •   aspix    5 年前

    你有一些 androidx 依赖关系已经存在。你最好换个电流 cardview 依赖于 androidx.cardview:cardview (最新版本是1.0.0)以保持一致性。也看看这篇文章 https://developer.android.com/jetpack/androidx/migrate